首页 > 解决方案 > 如何在 android studio 的屏幕中使用回收站视图和相关布局

问题描述

我在回收站视图下方有一个回收站视图和一个相对布局。我的相对布局由三个文本视图组成。我的回收站视图由三个文本视图和一个按钮组成。我的问题是回收器视图是单独滚动的,并且相对布局中的文本视图是固定的。但我希望两者都被滚动,这意味着在滚动屏幕滚动时应该同时针对回收站视图和相对布局进行滚动,但不能单独进行。滚动我的相对布局时,应将其附加到回收站视图的末尾。我为此进行了很多搜索,但没有搜索结果。所以,在这里结束了,请任何人帮助我。

标签: androidandroid-recyclerview

解决方案


您有 2 个选项,第一个(更好的)是创建一个页脚 ViewHolder 并将其添加到 RecyclerView 作为适配器中的最后一项。或者您可以简单地将视图包装在垂直 LinearLayout 中,然后将其包装在 NestedScrollView 中,如下所示:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

推荐阅读