android:layout“alignParentBottom=”;“真的”;将对话框活动的高度从换行内容更改为匹配父项

android:layout“alignParentBottom=”;“真的”;将对话框活动的高度从换行内容更改为匹配父项,android,android-activity,android-dialog,android-relativelayout,android-wrap-content,Android,Android Activity,Android Dialog,Android Relativelayout,Android Wrap Content,我在活动中有一个按钮,带有对话框样式。 这是我的活动的xml文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <

我在
活动
中有一个
按钮
,带有
对话框
样式。 这是我的
活动的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button" />

</RelativeLayout>
活动
显示为全屏,即使
android:windowFullscreen
为假!当我从
Activity
xml文件中删除
android:layout\u alignParentBottom=“true”
时,
Activity
height
更改为
wrap\u content
,没有问题。我想知道如何在不删除
按钮的属性的情况下解决此问题

在这里您可以看到显示活动的结果

使用android:layout\u alignParentBottom=“true”

没有android:layout\u alignParentBottom=“true”


创建对话框时尝试添加此运行时

mDialog.show();
Window window = mDialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
就像我在我的案件中所做的那样。。。
它是否有助于@Nava

您为什么不改用
FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="Button" />

</FrameLayout>

您可以通过设置属性来实现这一点

 android:layout_alignParentBottom="true"
以编程方式使用以下代码

    RelativeLayout relativeLayout = view.findViewById(R.id.relative_layout);
    Button button = relativeLayout.findViewById(R.id.button);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, view.getId());
    button.setLayoutParams(params);
在xml文件中,您需要设置一个id属性并删除android:layout\u alignParentBottom=“true”



你能详细说明具体的问题吗?我想要一个对话式的活动。没关系,我可以用对话框风格成功地开始活动,正如你在我的截图中看到的那样。我的问题是这个活动的高度,它是匹配父项而不是包装内容!我想要第二个屏幕截图,将android:layou\u alignParentBottom设置为“true”。因为在另一种情况下,我希望在没有对话框样式的情况下启动此活动,如果我删除此属性,则我的按钮不会位于屏幕底部。够清楚吗@瓦卡斯佩维茨先生感谢您的指导。我有一个复杂的布局,我想用RelativeLayout解决这个问题,而不是更改布局根目录。正如我所说,我有一个对话框样式的活动。我在Activity类中的setContentView()方法之后测试了您的代码。不幸的是,这对我不起作用!你是对的。看来这是解决这个问题的更好办法!但是我希望
RelativeLayout
能以某种方式自行处理这个问题。我会设法解决它,并让你知道。
    RelativeLayout relativeLayout = view.findViewById(R.id.relative_layout);
    Button button = relativeLayout.findViewById(R.id.button);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, view.getId());
    button.setLayoutParams(params);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/relative_layout"
android:layout_height="match_parent">

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button"
    android:text="Button" />

</RelativeLayout>