2015-06-19 175 views
1

我有這樣的佈局:問題與滾動視圖內佈局

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <EditText 
      android:id="@+id/username_edittext" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:background="@android:color/white" 
      android:gravity="center" 
      android:hint="@string/username" 
      android:textColor="@color/dark_grey" /> 

     <EditText 
      android:id="@+id/password_edittext" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:layout_below="@id/username_edittext" 
      android:background="@android:color/white" 
      android:gravity="center" 
      android:hint="@string/password" 
      android:textColor="@color/dark_grey" /> 

     <Button 
      android:id="@+id/login_button" 
      style="@style/ButtonStyle" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@id/password_edittext" 
      android:text="@string/login" /> 

    </RelativeLayout> 

</ScrollView> 

,它表現爲:

enter image description here

但我想對齊按鈕「Entrar」(login_button)在底部屏幕。 RelativeLayout不填充父項(ScrollView),因此按鈕中的alignParentBottom = true無法正常工作。

我該怎麼辦?

謝謝。

+0

爲什麼你需要有父視圖是滾動型?如果將RelativeLayout設置爲match_parent,它將始終與ScrollView的大小相同,並且不會滾動。 是否有您要在此視圖中滾動任何內容? –

回答

1

解決了!我在ScrollView中添加了android:fillViewport="true",並從按鈕中刪除了android:layout_below="@id/password_edittext"

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <EditText 
      android:id="@+id/username_edittext" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:background="@android:color/white" 
      android:gravity="center" 
      android:hint="@string/username" 
      android:textColor="@color/dark_grey" /> 

     <EditText 
      android:id="@+id/password_edittext" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:layout_below="@id/username_edittext" 
      android:background="@android:color/white" 
      android:gravity="center" 
      android:hint="@string/password" 
      android:textColor="@color/dark_grey" /> 

     <Button 
      android:id="@+id/login_button" 
      style="@style/ButtonStyle" 
      android:layout_width="match_parent" 
      android:layout_height="55dp" 
      android:layout_alignParentBottom="true" 
      android:text="@string/login" /> 

    </RelativeLayout> 

</ScrollView> 

enter image description here