2014-10-06 68 views
4

我在ScrollView中設置了fill_parent的RelativeLayout。但是,它只能水平填充,而不是垂直填充。我想在RelativeLayout中放置更多的內容,但首先我需要弄清楚爲什麼RelativeLayout不能填充ScrollView的高度。fill_parent不適用於ScrollView中的RelativeLayout

感謝您的任何幫助。

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/gray" 
    android:layout_below="@+id/previewButton" 
    android:layout_marginTop="10dp" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout" 
     android:layout_below="@+id/matchingWordsLabel" 
     android:background="@color/white" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     > 

     <TextView 
      android:id="@+id/titleLabel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:text="Title:" 
      /> 

      <EditText 
      android:id="@+id/title" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/titleLabel" 
      android:layout_alignBaseline="@+id/titleLabel" 
      android:ems="10" /> 
    </RelativeLayout> 
</ScrollView> 

回答

10

添加

android:fillViewPort="true" 

ScrollView

fill_parentmatch_parentScrollView內部的高度沒有意義,它被忽略 - 否則就不需要滾動。 fillViewPort="true"使滾動視圖佔據屏幕上可用的所有垂直空間。

-1

因爲ScrollView只能有一個孩子將LinearLayout放在裏面。在LinearLayout中放置RelativeLayout。將高度設置爲wrap_content。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/svRecord" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="center_horizontal" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:orientation="vertical" 
    android:paddingLeft="12dp" 
    android:paddingRight="12dp" 
    android:visibility="visible" > 
相關問題