ScrollView嵌套RecyclerView

来源:互联网 发布:新手学美工 编辑:程序博客网 时间:2024/05/21 02:33

有时候我们需要实现ScrollView嵌套RecyclerView的效果:

<RelativeLayout>    <ScrollView android:id="@+id/myScrollView">        <LinearLayout>            <unrelated data>不相关的布局</unrealated data>            <android.support.v7.widget.RecyclerView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:id="@+id/my_recycler_view"/>        </LinearLayout>    </ScrollView></RelativeLayout>

有以下方法:
1. 使用NestedScrollView代替ScrollView

recyclerview.setNestedScrollingEnabled(false);

ViewHolder的高度:

android:layout_height="wrap_content"

参考:http://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working

  1. 为RecyclerView增加Header

  2. 修改Adapter(未测试),参考:http://blog.csdn.net/revival_liang/article/details/52201099