Align Recycler View above linear layout

The list of things expected in the outout 1.a linear layout to the buttom of the activity as shown in the expected image 2.a recycler view above the linear layout to achieve the scrolling funtionality as shown in the expected image

The problem can be solved if I give the height to the recycler view.But in this case the layout won't be responsive to the samller sized screens

How can I achieve it? xmlfile.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:numberpicker="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=".CartPage">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:padding="20dp">


        <ImageView
            android:id="@+id/back_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_arrow_back_black_24dp" />

        <TextView
            android:id="@+id/product_buy"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_marginLeft="20dp"
            android:layout_toRightOf="@+id/back_icon"
            android:fontFamily="@font/carter_one"
            android:text="My Cart"
            android:textColor="@color/black"
            android:textSize="20sp"
            tools:ignore="RtlCompat" />


    </RelativeLayout>



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

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

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/product_recycler"
                android:layout_width="match_parent"
                android:layout_height="400sp"
                android:padding="0dp" />

// this is the buttom recycler

            <LinearLayout
                android:layout_alignParentBottom="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/buttom"
                android:gravity="bottom|end"
                android:layout_gravity="bottom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/border_gray"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:id="@+id/details"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/border_gray"
                    android:fontFamily="sans-serif"
                    android:lineHeight="28dp"
                    android:padding="5dp"
                    android:text="Price Details"
                    android:textColor="@color/grey_400"
                    android:textSize="18sp"
                    tools:ignore="RtlCompat" />



            </LinearLayout>
        </LinearLayout>
    </LinearLayout>


</LinearLayout>

This is the expected output

The out which I am geting is as follows

Upvotes: 1

Views: 578

Answers (1)

Sdghasemi
Sdghasemi

Reputation: 5598

If you wish to tell your RecyclerView to fill the left over space of your LinearLayout you have to use the following layout_height and layout_weight on your RecyclerView:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/product_recycler"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:padding="0dp" />

Upvotes: 1

Related Questions