2015-06-19 184 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