Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在线性布局上方对齐回收器视图_Android_Android Studio_Android Layout_Android Recyclerview - Fatal编程技术网

Android 在线性布局上方对齐回收器视图

Android 在线性布局上方对齐回收器视图,android,android-studio,android-layout,android-recyclerview,Android,Android Studio,Android Layout,Android Recyclerview,在outout中预期的事情列表 1.活动按钮的线性布局,如预期图像所示 2.线性布局上方的回收器视图,以实现预期图像中所示的滚动功能 如果我给回收者视图的高度,这个问题可以解决。但在这种情况下,布局将不会对较小尺寸的屏幕做出响应 我怎样才能做到呢? xmlfile.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/a

在outout中预期的事情列表 1.活动按钮的线性布局,如预期图像所示 2.线性布局上方的回收器视图,以实现预期图像中所示的滚动功能

如果我给回收者视图的高度,这个问题可以解决。但在这种情况下,布局将不会对较小尺寸的屏幕做出响应

我怎样才能做到呢? 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" />


如果您希望让您的
回收视图
填充
线性布局的剩余空间
,您必须在
回收视图上使用以下
布局高度
布局重量

<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" />

此代码绝对有效。有时,解决方案非常简单,但我们对此思考了很多。android:layout_weight=“1”是最简单的解决方案,谢谢您,先生。
<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" />