Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何设置以对话框为主题的活动的百分比宽度_Android_Android Layout - Fatal编程技术网

Android 如何设置以对话框为主题的活动的百分比宽度

Android 如何设置以对话框为主题的活动的百分比宽度,android,android-layout,Android,Android Layout,我有一个带有对话框主题的活动(theme.Holo.DialogWhenLarge)。它看起来太窄了,我希望它能占据更大的屏幕比例。我试图通过重写和属性来实现这一点 我的活动使用的主题如下所示 <style name="MyTheme" parent="@android:style/Theme.Holo.DialogWhenLarge"> <item name="android:windowMinWidthMajor">90%</item> &

我有一个带有对话框主题的活动(
theme.Holo.DialogWhenLarge
)。它看起来太窄了,我希望它能占据更大的屏幕比例。我试图通过重写和属性来实现这一点

我的活动使用的主题如下所示

<style name="MyTheme" parent="@android:style/Theme.Holo.DialogWhenLarge">
    <item name="android:windowMinWidthMajor">90%</item>
    <item name="android:windowMinWidthMinor">90%</item>
</style>

90%
90%

但是,
windowMinWidthMajor
windowMinWidthMinor
似乎没有效果。谁能解释我做错了什么

为android设置百分比是不可能的,但有一种方法。我所做的是获取屏幕宽度,然后将其乘以我希望我的视图或项目的百分比(例如:如果我想让某个内容填充40%的宽度,那么它将是屏幕宽度*0.4)

此属性的文档会说:“可能是一个分数,它是一个浮点数字,附加了%p或%p,例如“14.5%”(如果我在SDK min 23上使用
parent=“android:style/Theme.Holo.Light.Dialog”
,这对我来说确实有效
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Some code here
        setWindowHeight(90);
    }
    /**
     * Set percentage width height
     * @param percent percent from current size. From 0 to 100.
     */
    private void setWindowHeight(int percent){
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int screenHeight = metrics.heightPixels;
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.height = (int)(screenHeight*percent/100);
        this.getWindow().setAttributes(params);
    }