如何在NestedScrollView内使用RecyclerView ?
设置适配器后,RecyclerView内容不可见。
更新布局代码。
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/keyline_1">
</RelativeLayout>
<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
<android.support.v7.widget.RecyclerView
android:id="@+id/conversation"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
如果您使用的是RecyclerView-23.2.1或更高版本。下面的解决方案可以很好地工作:
在你的布局中添加这样的RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/review_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
在你的java文件中:
RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager=new LinearLayoutManager(getContext());
layoutManager.setAutoMeasureEnabled(true);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(new YourListAdapter(getContext()));
这里layoutManager.setAutoMeasureEnabled(真正的);会成功的。
查看这个问题和这个开发者博客以获得更多信息。
我在NestedScrollView内使用RecyclerView,它为我工作。我必须记住的唯一问题是NestedScrollView只接受一个子视图。所以在我的情况下,我使用的LienearLayout视图组,它是住房我的RecyclerView加上其他一些我需要的视图。
我经历了一个问题,把我的RecyclerView内的NestedScrollView。我意识到我的RecyclerView的内容滚动变慢了。
我后来意识到我的RecyclerView正在接收滚动事件,因此与NestedScrollView的滚动行为相冲突。
所以为了解决这个问题,我不得不禁用我的RecyclerView的滚动功能与这个方法movieListNewRecyclerView.setNestedScrollingEnabled(false);
你可以在我的Instagram上查看我实际做了什么。这是我的instagram账号elix03