Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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 对话框正在缩小,即使所有父布局\u宽度设置为填充\u父布局_Android_Layout_Dialog - Fatal编程技术网

Android 对话框正在缩小,即使所有父布局\u宽度设置为填充\u父布局

Android 对话框正在缩小,即使所有父布局\u宽度设置为填充\u父布局,android,layout,dialog,Android,Layout,Dialog,这里遇到了另一个奇怪的行为。这一次,我的对话框正在缩小宽度,尽管将所有父布局的宽度设置为填充父布局。这是图片 我已经尝试将其作为一个活动,在清单中将主题设置为对话框。但它的表现仍然是一样的。但是,当我将第一个文本视图“用户协议”的布局宽度设置为填充父项时,它就会变得正常。但我不理解这种行为,因为它不应该依赖于TextView的宽度来获得自己的宽度。请告诉我是否有其他有效的方法来处理这类情况。我的布局代码如下: <?xml version="1.0" encoding="utf-8"?>

这里遇到了另一个奇怪的行为。这一次,我的对话框正在缩小宽度,尽管将所有父布局的宽度设置为填充父布局。这是图片

我已经尝试将其作为一个活动,在清单中将主题设置为对话框。但它的表现仍然是一样的。但是,当我将第一个文本视图“用户协议”的布局宽度设置为填充父项时,它就会变得正常。但我不理解这种行为,因为它不应该依赖于TextView的宽度来获得自己的宽度。请告诉我是否有其他有效的方法来处理这类情况。我的布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@layout/gradientback"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="User Agreement"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#B80303" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="3dip"
        android:background="?android:attr/listDivider" >
    </View>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <CheckBox
            android:id="@+id/checkBoxForTermsId"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#7B4302"
            android:text="I Agree The Terms &amp; Conditions" >
        </CheckBox>

固定父布局的宽度

 android:layout_width="400dp"
fill_parent适用于活动xml,但对于对话框,必须设置宽度

如果您正在寻找通用解决方案,请在父布局中将图像设置为背景,就像我们将图像放置在不同的可绘制文件夹中以支持多个屏幕一样

您还可以使用将宽度设置为全屏

dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
为什么会通过对话框显示此行为

对话框主题作为其性质的一部分,将顶级窗口布局设置为“换行内容”。您可以尝试手动设置窗口布局宽度和高度以填充父窗口

参考了这一点


这对我很有用。

这个词是“示例”而不是“示例”!:-)@波弗雷多:如果我说那是坦普尔呢……:)呵呵,我也在想,但我选择的可能性是相反的;)但说真的,我和你的DialogFragment也有同样的问题,我对解决办法很好奇!嗯……让我们看看是否还有其他人遇到过这个怪人……:)我想他正在寻找一个更通用的解决方案,可以在不同的设备上工作。@bofredo我已经更新了答案。谢谢你的评论。我已经尝试过在背景中放置一个图像,它解决了这个问题,但我不想这样做,因为它增加了我的应用程序的大小。但问题是为什么它取决于我的标题文本视图的宽度,而不是任何其他布局或视图…再次更新答案。你的答案的下半部分有效…感谢…+1提供对话框主题的信息…:)
dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
setContentView(R.layout.layout_name);
    getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);