Android RelativeLayout中的奇怪按钮行为

Android RelativeLayout中的奇怪按钮行为,android,layout,button,android-relativelayout,Android,Layout,Button,Android Relativelayout,我在我的应用程序中有一个自定义对话框,它是从活动派生出来的,使用RelativeLayout,所有定位和属性都由XML文件处理,而代码中没有。我的布局正是我想要的,但是由于对话框中某些项目的长度,一些信息行会换行到下一行。这不是问题,除了对话框中的“关闭”按钮在这些情况下看起来像是有人坐在上面 这是来自emulator的屏幕截图,显示的按钮很好,但我希望在描述文本的右侧添加一些填充,这样它就不会与对话框的右侧对接: 看到这一点,我在布局文件中添加了android:layout_marginRi

我在我的应用程序中有一个自定义对话框,它是从
活动
派生出来的,使用
RelativeLayout
,所有定位和属性都由XML文件处理,而代码中没有。我的布局正是我想要的,但是由于对话框中某些项目的长度,一些信息行会换行到下一行。这不是问题,除了对话框中的“关闭”按钮在这些情况下看起来像是有人坐在上面

这是来自emulator的屏幕截图,显示的按钮很好,但我希望在描述文本的右侧添加一些填充,这样它就不会与对话框的右侧对接:

看到这一点,我在布局文件中添加了
android:layout_marginRight=“5dp”
,希望得到我的边距,这似乎可以做到——我也得到了我的换行符——但按钮不对。对话框的高度没有改变,因为描述现在正在换行

这是我的完整布局XML。这是我第一次使用
RelativeLayout
,希望这是我忽略的简单的东西

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        <ImageView
                android:id="@+id/achievement_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="7dp"
                android:contentDescription="@string/achievement_icon" />
        <TextView
                android:id="@+id/achievement_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:textColor="#ffffff"
                android:textStyle="bold"
                android:layout_toRightOf="@+id/achievement_icon" />
        <TextView
                android:id="@+id/achievement_gamerscore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#ffffff"
                android:textStyle="bold"
                android:layout_marginLeft="5dp"
                android:layout_below="@+id/achievement_name"
                android:layout_toRightOf="@+id/achievement_icon" />
        <TextView
                android:id="@+id/achievement_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="7dp"
                android:layout_marginRight="5dp"
                android:layout_alignLeft="@+id/achievement_icon"
                android:layout_below="@+id/achievement_icon" />
        <TextView
                android:id="@+id/achievement_earned"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="7dp"
                android:layout_marginRight="5dp"
                android:layout_alignLeft="@+id/achievement_description"
                android:layout_below="@+id/achievement_description" />
        <Button
                android:id="@+id/cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="7dp"
                android:layout_centerHorizontal="true"
                android:text="@string/button_close"
                android:layout_below="@+id/achievement_earned" />
    </RelativeLayout>

问题是按钮的空间不够了

要为按钮腾出空间,请执行以下操作:

1.)您可以将按钮移动到右上角,并将其显示为x

2.)您可以限制description TextView的大小,并通过在scrollview中包围TextView将其设置为垂直滚动(不需要scrollview也可以使用更简洁的方法来实现这一点,但您明白我的意思

3.)减小按钮的高度

此外,我也会对应用程序手机在不同屏幕分辨率/密度的手机上的外观持谨慎态度。因此,在设计UI时请注意这一点

我的意思是:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:fillViewport="true">

     <TextView
            android:id="@+id/achievement_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:layout_marginRight="5dp"
            android:layout_alignLeft="@+id/achievement_icon"
            android:layout_below="@+id/achievement_icon" />

</ScrollView>

但是,您需要将“成就描述”文本视图的高度限制为某个值,而不是包装内容