首页 > 解决方案 > 当回收站视图中的项目数量很少时,协调器布局太大

问题描述

我在 Coordinator 布局中遇到 RecyclerView 问题。如果 recycler view 中的 item 数量较少,则 Coordinator 的 size 大于 screen。滚动到最后,recycler view的空间+额外空间就是屏幕高度的大小。这是正常行为吗?还是有办法解决?如果我将回收器高度设置为“match_parent”,那么整个回收器视图就是屏幕的大小......

编辑:当没有足够的项目时,我希望视图不要滚动。并且如果屏幕下方有 1-2 个项目,则回收器不应与整个屏幕一样高,而只能滚动少数项目。

    <android.support.design.widget.CoordinatorLayout 
        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"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".MainActivity"
        android:background="#dddddd">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp"
            android:background="#777777">

            <FrameLayout
                android:id="@+id/cardMenu"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:paddingTop="16dp"
                android:orientation="vertical"
                app:layout_scrollFlags="scroll">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textColor="#fff"
                    android:text="Red Dwarf characters"/>
            </FrameLayout>

        </android.support.design.widget.AppBarLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:background="#aaaaaa"
            android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" 
        />
    </android.support.design.widget.CoordinatorLayout>

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

回收站视图高度设置为 match_parent 在此处输入图像描述

标签: androidandroid-layoutandroid-recyclerviewandroid-coordinatorlayout

解决方案


推荐阅读