Expiredmind
Expiredmind

Reputation: 808

LinearLayout below dynamic RecyclerView listview

I have a Dynamic list and the static linear layout below last item. When list is empty the LinearLayout is on the top of the page.

Whenever I have added element into the list the LinearLayout is moving below the last item of the list. When the list became long the static LinearLayout should be stay at the end of the screen. I have draw some examples for better understanding.

enter image description here

But whenever ive added 7 element, my linear layout is hiding below list.

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/app_margin"
        android:id="@+id/group_manage_list_view"
        android:paddingBottom="40dp"
        />

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_below="@+id/group_manage_list_view"
          >

            <Button
                android:layout_width="34dp"
                android:layout_height="34dp"
                android:background="@drawable/ic_add_circle_outline_white_24dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/app_margin"
                android:backgroundTint="@color/headline_grey"
                android:id="@+id/create_group_button_click"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/add_group"
                android:layout_marginLeft="@dimen/app_margin"
                android:layout_gravity="center_vertical"
               />


        </LinearLayout>

    </RelativeLayout>

Upvotes: 1

Views: 185

Answers (2)

Amrish Kakadiya
Amrish Kakadiya

Reputation: 1023

I think you need to use NestedScrollView, here is sample code. hope this may help you.

<?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.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Seomthing" />
        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>

Upvotes: 1

Amit Vaghela
Amit Vaghela

Reputation: 22955

you can use android:layout_weight to achieve this but you have to maintain visibility of your recycleview and linearlayout below that, say if array size is greater than zero than make it visible else not and vice-versa

<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/group_manage_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.8"
        android:padding="10dp"
        android:paddingBottom="40dp"
        android:visibility="gone" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:minHeight="50dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/create_group_button_click"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:layout_gravity="top"
            android:layout_marginLeft="10dp"
            android:background="@drawable/ic_launcher_background"
            android:backgroundTint="@color/colorAccent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginLeft="10dp"
            android:text="add_group" />

    </LinearLayout>

</LinearLayout>

Upvotes: 1

Related Questions