I have a template in Android, I have an image, a title and a listview but when I put a button below the listview it is hidden on the screen, I have to put it above the listview because if it is not hidden but I would like it to be below, that has happened to me regularly when I try to put components below a listview. I attach my code.
Thanks.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tema_fondo">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/linearPadre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/tema_color_blanco_transparente"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="65dp"
android:src="@drawable/tema_icono_paso_3" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/idHeaderCobertura"
android:layout_width="match_parent"
android:layout_height="80dp"
android:src="@drawable/cobertura" />
<TextView
android:id="@+id/textAseguradora"
android:textAlignment="center"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity= "center"
android:layout_below="@+id/idHeaderCobertura"
android:textColor="@color/colorGreen"
android:text="Aseguradora"
android:ems="18"/>
<ListView
android:id="@+id/coberturas_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textAseguradora"
android:drawSelectorOnTop="true"
android:divider="@null"
tools:listitem="@layout/list_item_detalle_cobertura" />
<Button
android:text="Continuar"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/radio_button_azul"
android:gravity="center"
android:layout_below="@+id/coberturas_list"
android:layout_gravity="center"
android:textColor="@color/colorWhite"
android:id="@+id/btnContinuar" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
That's because
ListView
you are assigning the valuewrap_content
to the propertyandroid:layout_height
, which is what defines the height that the ListView will have. Being wrap_content, the ListView will be as large as the number of elements it has. If your ListView has 20 items, the list will scroll off the screen and you will have to scroll to see the full list. And if you have any items below the ListView, that will also roll off the screen.To fix your problem, give the ListView a fixed (static) size. Like for example, a height of 400dp:
android:layout_height="400dp"
. Try different values until the ListView is a size that allows room to color the button below it without it going off screen.edited
Another possible solution is the following. Place the
ListView
above of the button with the property:android:layout_above="@id/coberturas_list"
. That way you can usewrap_content
in the ListView and not have to worry about screen sizes.You already have an answer marked as valid but I'll pass you my layout code. With this code you don't have to give a fixed size to the listview.
The listview is displayed in full screen with a button at the bottom of the listview, try it out and see if you like it.
The interface design has some problems:
Here is a simplified version of the code, although different, which I think can be adjusted to your needs.
I hope it helps.