2014-06-05 64 views
2

所以我有兩個「部分」我的屏幕。我有頂部是ScrollView和底部是隨機文本。底部的隨機文本將始終在不斷變化的大小,所以有時可能需要40dp,有時20dp等。如何使查看填充剩餘空間

我的問題是,有沒有辦法使底部動態(沒有文本丟失),並使頂部滾動視圖適應新的尺寸,並根據底部使用的部分來限制其自身尺寸以「填充剩餘空間」?

像這樣:

enter image description here enter image description here

正如你所看到的,滾動視圖只是填補剩餘的可用空間。

我正在尋找一種僅使用XML的解決方案

需要幫助!

回答

11

您可以試試這個。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/bottomTextView"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="500dp" 
      android:background="@android:color/holo_red_dark" 
      android:text="Test" /> 
    </LinearLayout> 
</ScrollView> 

<TextView 
    android:id="@+id/bottomTextView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@android:color/darker_gray"/> 

或者

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="500dp" 
      android:background="@android:color/holo_red_dark" 
      android:text="Test" /> 
    </LinearLayout> 
</ScrollView> 

<TextView 
    android:id="@+id/bottomTextView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/darker_gray"/> 

3

在垂直LinearLayout中包裝兩個視圖;

查看頂部:height = 0dp,weight = 1; 查看底部的whitch:height = wrap_content