在nestedscrollview中的Recyclerview

时间:2015-12-27 18:38:56

标签: android android-recyclerview nestedscrollview

我有一个像这样的布局

TextView 1

TextView 2

TextView 3

ImageView

Recyclerview

[第1至10项 垂直组织]

现在,当我滚动页面时,整个页面必须滚动,而不是单独的Recyclerview。 这是android中非常常见和旧的东西,我得到的解决方案是实现 Is there an addHeaderView equivalent for RecyclerView?

我不想遵循这种方法,因为它是一个非常糟糕的解决方案。我觉得在nestedscrollview中实现recyclerview可能会解决我的问题,我采取了正确的方法吗?或者我应该使用协调员布局? 任何帮助都非常感谢,您能否提供一些符合我要求的链接。

1 个答案:

答案 0 :(得分:3)

我找到了此查询的解决方案。看看这个布局, 想法是有一个

CoordinatorLayout作为根

- AppBar布局恰好是Coordinator的直接子布局

托管将具有不同textview / radiobutton的相对布局(您想要添加为标题类型的东西)

---关闭appbarlayout

在appbarlayout正下方添加recyclerview。

它会正常工作,查看我使用过的布局,不要忘记在适当的位置添加应用:行为。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                     android:layout_width="match_parent"
                                                     xmlns:app="http://schemas.android.com/apk/res-auto"
                                                     android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent">

        <RelativeLayout
                android:layout_width="match_parent"
                app:layout_scrollFlags="scroll|enterAlways"
                android:layout_height="wrap_content"
                android:id="@+id/relLayout">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="Large Text"
                    android:id="@+id/textView"
                    android:layout_marginLeft="97dp"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginTop="37dp"/>

                <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="New RadioButton"
                        android:id="@+id/radioButton"
                        android:layout_below="@+id/textView"
                        android:layout_alignLeft="@+id/textView"
                        android:layout_marginTop="49dp"/>
            </RelativeLayout>
        </android.support.design.widget.AppBarLayout>

     <android.support.v7.widget.RecyclerView
           app:layout_behavior="@string/appbar_scrolling_view_behavior"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/padding_small"
             android:layout_below="@+id/relLayout"
             android:id="@+id/recyclerview_settings_list"
             android:scrollbars="vertical"/>

</android.support.design.widget.CoordinatorLayout>
相关问题