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

Почему вы должны иметь родительский вид быть ScrollView? Если вы установите RelativeLayout в match_parent, он будет всегда того же размера, что и ScrollView, и ничто никогда не будет прокручиваться. Есть ли какой-либо контент, который вы хотите прокрутить в этом представлении? –

ответ

1

Решенный! Я добавил android:fillViewport="true" в ScrollView и удалил 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

Смежные вопросы