Search code examples
androidlistviewlayoutoverlapping

Android ListView overlapping


Im trying to have LinearLayout below a ListView, which is pretty long, so the ListView is overlapping the layout below.. I have tried several ways, sometimes it looks good in the preview, but not in the emulator at runtime. This is my simple layout so far (had several others, that didnt work as well). Im getting mad to be stucked with this poor problem. Can anyone solve my puzzle please?

<?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/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="send"
        android:text="@string/odeslat" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="reset"
        android:text="@string/reset" />
</LinearLayout>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/footer">

    <ListView
        android:id="@+id/questionlst"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>
</RelativeLayout>

Solution

  • You just needed to add android:layout_alignParentBottom="true" to your footer LinearLayout. That's it! You get something like this:

    <?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/footer"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="send"
            android:text="hey" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="reset"
            android:text="hey" />
    </LinearLayout>
    
    <ListView
        android:id="@+id/questionlst"
        android:layout_above="@id/footer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    Just checked it, it works in Android Studio.