2012-02-17 17 views
31

Quiero implementar esto: Un ScrollView que contiene muchos elementos (ImageViews, TextViews, EditTexts, etc.) y luego ScrollView algunos botones (que son ImageViews personalizados) que aparecen siempre exactamente en la parte inferior de la pantalla.Android ScrollView y botones en la parte inferior de la pantalla

Si uso el atributo android: fillViewport = "true", entonces si los elementos de ScrollView son demasiado grandes para caber en el tamaño de la pantalla, los botones se vuelven invisibles. Si utilizo el atributo android: Weight = 1, ScrollView obtiene solo el 50% de la pantalla cuando la pantalla es grande y puede caber (quiero que los botones tengan un pequeño porcentaje, alrededor del 10%). Si configuro Android: Peso a valores más grandes, los botones aparecen muy pequeños.

Por favor ayuda! ¡Tal vez es algo simple que pasé por alto pero me he estado golpeando la cabeza por horas!

+0

favor mostrar el archivo de diseño –

Respuesta

72

Acaba de crear y lo probé Parece que quieres.

<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout 
      android:id="@+id/buttons" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center" 
      android:layout_alignParentBottom="true"> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Custom Button1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Custom Button2"/> 
    </LinearLayout> 

    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@id/buttons"> 
     <!--Scrollable content here--> 
     <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical">     
      <TextView 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="test text" 
        android:textSize="40dp"/> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 
+0

que funciona muy bien! ¡Gracias! – george

+0

Tuve un problema similar. Funcionó bien con esta solución – zolio

+0

Cuando ScrollView se llena, ¿no se escribirá sobre los botones? – FractalBob

2

ScrollView no puede ajustarse a la pantalla, ya que lo puso en una disposición lineal, en forma de diseño de manera lineal en la pantalla,

simplemente tratar de hacer ScrollView como elemen root en diseño xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <!-- Here you can put some XML stuff and BOOM! your screen fit to scrollview --> 

    </LinearLayout> 
</ScrollView> 
3

Esto funcionó para mí. Dé a la vista de desplazamiento un peso de 1. Coloque todos los demás widgets siguiendo la vista de desplazamiento en un diseño. La vista de desplazamiento crecerá lo suficiente como para no bloquear el resto.

Widgets in scroll view and rest at bottom

9
<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
      android:orientation="vertical"> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello World" 
      /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hallo Welt" 
      />  
     </LinearLayout> 
    </ScrollView> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0"> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Go next page" 
      android:layout_alignParentRight="true" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

hola estoy teniendo el diseño con el encabezado y el scrolview de los campos de entrada y el pie de página cuando el teclado está llegando ese pie de página también se desplaza hacia arriba.me gusta arreglar ese pie de página en la parte inferior. Ayúdame – Harsha

+0

Funcionó. Me costó encontrar una solución para las últimas 3 horas. – chanakya

Cuestiones relacionadas