Search code examples
androidandroid-layoutandroid-recyclerviewandroid-checkboxfastadapter

RecyclerView pushes checkboxes out of the screen


In an Android app using FastAdapter I am trying to display 3 checkboxes underneath a RecyclerView.

This should give the user a possibility to filter the list of games by wins, losses, draws.

However the full screen height is filled by the RecyclerView (pardon the non-english texts below):

app screenshot

The 3 checkboxes are only shown at the beginning, while the data is loaded via HTTP. And then they disappear as if the RecyclerView has pushed them away or overlayed them.

Below is my layout file, how could I fix my problem? I would also prefer the 3 checkboxes to be in 1 row if there is enough width (i.e. some flexible layout, which would break the line automatically):

<?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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical" />

    <CheckBox
        android:id="@+id/wonBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Wins" />

    <CheckBox
        android:id="@+id/lostBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Losses" />

    <CheckBox
        android:id="@+id/drawBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Draws" />

</LinearLayout>

UPDATE:

No luck with RelativeLayout sofar (the checkbox overlay the list):

app screenshot 2


Solution

  • Use a relative layout:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/llbottom"
        android:scrollbars="vertical" />
    
    <LinearLayout
        android:id="@+id/llbottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">
    
        <CheckBox
            android:id="@+id/wonBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Wins" />
    
        <CheckBox
            android:id="@+id/lostBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Losses" />
    
        <CheckBox
            android:id="@+id/drawBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Draws" />
    
    </LinearLayout>