0

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

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

2 Answers2

1

EDITED: It's not the best solution but it works. Use android:layout_height like this

<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="0dp"
        android:layout_weight="4"
        android:scrollbars="vertical" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        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>

</LinearLayout>
Peyman
  • 941
  • 8
  • 28
  • No, this resulted in a huge list, which had the checkboxes at the very bottom. While I need the checkboxes always be on the (bottom of) screen. But still thanks for answering - upvoted – Alexander Farber Jul 29 '18 at 18:03
  • 1
    OK i misunderstood your question. I edited my answer. it should work – Peyman Jul 29 '18 at 19:23
1

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>