2012-05-06 113 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的高度限制爲一定值,而不是包裹內容。