Выровнять вид ресайклера над линейной компоновкой - PullRequest
1 голос
/ 07 мая 2020

Список вещей, ожидаемых на выходе 1. линейный макет до нижней части действия, как показано на ожидаемом изображении 2. вид ресайклера над линейным макетом для достижения функциональности прокрутки, как показано на ожидаемом изображении

Проблема может быть решена, если я укажу высоту для вида ресайклера. Но в этом случае макет не будет реагировать на экраны размера samller

Как я могу этого добиться? 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" />

// это переработчик нижней части

            <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

1 Ответ

1 голос
/ 07 мая 2020

Если вы wi sh, чтобы указать RecyclerView на заполнить оставшееся пространство вашего LinearLayout, вы должны использовать следующие layout_height и layout_weight на своем 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" />
...