2010-05-11 69 views
1

在用作對話框的follwing佈局中,我無法讓我的相對layuot視圖縮小。 在下面的示例中,如果沒有太多實際內容,scrollview將始終展開以填充整個對話框,該對話框看起來非常難看。RelativeLayout高度不縮小

我已經嘗試了fill_parent,wrap_content等沒有成功的大多數組合。

問題似乎是將按鈕設置爲「align_bottom」將導致對話框填充其高度。但如果我更改順序,並且必須將按鈕放置在滾動視圖下方,如果顯示大量內容,按鈕將不可見...

解決方法(我認爲這是一個非常醜陋的解決方案)是設置保證金滾動視圖上的底部,然後按鈕上的相同負邊距頂部。但我不確定這將如何看待不同的顯示。

請幫幫忙/魯達什

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ScrollView 
     android:id="@+id/ScrollView01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/dialogCloseButton" 
     android:layout_alignParentTop="true" > 

     <LinearLayout 
      android:id="@+id/dialogContent" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingBottom="10dp" > 

      <TextView 
       android:id="@+id/TextView01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 
      </TextView> 
     </LinearLayout> 
    </ScrollView> 

    <Button 
     android:id="@+id/dialogCloseButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Close" > 
    </Button> 

</RelativeLayout><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ScrollView 
     android:id="@+id/ScrollView01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/dialogCloseButton" 
     android:layout_alignParentTop="true" > 

     <LinearLayout 
      android:id="@+id/dialogContent" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingBottom="10dp" > 

      <TextView 
       android:id="@+id/TextView01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 
      </TextView> 
     </LinearLayout> 
    </ScrollView> 

    <Button 
     android:id="@+id/dialogCloseButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Close" > 
    </Button> 

</RelativeLayout> 

回答

0

滾動型是特殊類型的FrameLayout的。這意味着它將始終從父佈局的左上角開始。效果與其他視圖重疊,並且RelativeLayout設置不起作用。解決方案是將StrollView放在單獨的佈局中(例如LinearLayout)。