0

I want to place a View (and in particular a View Group) at the end of a RecyclerView. My RecyclerView content extends beyond the display height, so I want that after last item appears another View Group.

I tried two different approach, but none of them had the desired effect. That is:

Attempt 1

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".StandingsActivity">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*">

    <TableRow
        android:padding="5dp">

        <!-- the table layout appears well above the RecyclerView -->

    </TableRow>

</TableLayout>

<!-- also the following view appears well above the RecyclerView-->
<View
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:background="@color/accent" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview_standings"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<!-- the view starting from here are fixed at screen bottom-->
<View
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:background="@color/accent" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:text="Legend"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/accent"
    android:textStyle="italic"
    android:text="@string/standings_table_legend" />

In this first attempt, the last views are fixed at the end of the screen and the items of RecyclerView scroll inside the middle of the screen. Not going so far beyond the end of the screen.

Attempt 2

<RelativeLayout 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"
tools:context=".StandingsActivity">

<TableLayout
    android:id="@+id/table"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*">

    <TableRow
        android:padding="5dp">

        <!-- the table layout appears well above the RecyclerView -->

    </TableRow>

</TableLayout>
<View
    android:id="@+id/view1"
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:layout_alignParentTop="true"
    android:layout_below="@id/table"
    android:background="@color/colorAccent" />

<LinearLayout
    android:id="@+id/rec_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/view1"
    android:orientation="vertical">

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@id/rec_container">

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:background="@color/colorAccent" />

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/view2"
        android:text="Legend"
        android:textColor="@color/colorAccent"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/text1"
        android:textColor="@color/colorAccent"
        android:textStyle="italic"
        android:text="@string/standings_table_legend" />
</RelativeLayout>

In the second attempt the entire view group under the RecyclerView is never showed, the screen ends with last item of RecyclerView.

Someone can suggest how to solve this problem through xml? Thanks in advance

Gil
  • 111
  • 1
  • 7
  • 1
    I think that you can probably use the footer part of this answer: https://stackoverflow.com/a/29168617/3390459 – emerssso Mar 30 '18 at 20:06
  • 1
    You want a `ViewGroup` to appear below `RecyclerView` but that `ViewGroup` should appear only when the last item of `RecyclerView` is showing? Is that correct? Then you can try `NestedScrollView` or **Heterogenous** `RecyclerView` adapter. – Hussain Mar 30 '18 at 20:07
  • Possible duplicate of [Android 5.0 - Add header/footer to a RecyclerView](https://stackoverflow.com/questions/26448717/android-5-0-add-header-footer-to-a-recyclerview) – Reaz Murshed Mar 30 '18 at 20:28
  • Please see the answer here to add a footer in your `RecyclerView` - https://stackoverflow.com/a/31154402/3145960 – Reaz Murshed Mar 30 '18 at 20:29

0 Answers0