2012-05-06 110 views
0

我的应用程序中有一个自定义对话框,其编号从Activity下降,并使用RelativeLayout,其中所有位置和属性均由XML文件处理,而代码中没有任何属性。我的布局完全符合我的要求,但由于对话框中某些项目的长度,信息的某些行会换行到下一行。这不是一个问题,除了在这种情况下对话框中的关闭按钮看起来像是有人坐在它上面的事实。RelativeLayout中的奇怪按钮行为

这是从展示该按钮罚款模拟器截图,但我想在说明文字的右边一些填充,所以它不抵靠在该对话框的右侧:

Good button, but needs right margin

看到这个,我将android:layout_marginRight="5dp"添加到布局文件,希望得到我的保证金,这似乎是做 - 我得到我的包装 - 但按钮是不正确的。当我期待它时,对话框的高度不会改变,因为描述现在正在包装一条线。

Good wrapping, but button squished

这里是我的完整布局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> 

回答

0

问题是您的按钮空间不足。

为了腾出空间给按钮:

1)你也许可以移动的按钮右上方显示这就像一个X。

2)你可以限制说明书的TextView的大小并将其设置为通过在滚动视图TextView的周围(简洁的方式来做到这一点也无需了滚动的垂直滚动,但你明白我的意思。

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> 

然而,你将需要在“ACHIEVEMENT_DESCRIPTION”的TextView的高度限制为一定值,而不是包裹内容。