如何在NestedScrollView中使用RecyclerView [英] How to use RecyclerView inside NestedScrollView
本文介绍了如何在NestedScrollView中使用RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的布局:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
效果很好.我可以平滑滚动RecyclerView
而不滚动父视图.
It works well. I can scroll RecyclerView
smoothly without scrolling parent view.
现在,我必须像这样将RecyclerView
放在FrameLayout
内:
Now I have to put the RecyclerView
inside a FrameLayout
like this:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<FrameLayout
android:id="@+id/review_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="@+id/empty_view"
layout="@layout/review_empty_view"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
现在,我无法平滑滚动RecyclerView
.
我想要的是:平滑滚动RecyclerView
而不滚动父视图.我该怎么办?
Now I cannot scroll the RecyclerView
smoothly.
All I want is: scroll RecyclerView
smoothly without scrolling parent view. What should I do?
编辑:这是我的review_empty布局:
EDIT: Here is my review_empty layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/shopping_review_empty" />
<android.support.v4.widget.Space
android:layout_width="32dp"
android:layout_height="0dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shopping_no_review_message" />
</LinearLayout>
推荐答案
只需启用嵌套滚动即可启用平滑滚动视图.
just enable nestedscrolling that will enable smooth scrollview.
RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
这篇关于如何在NestedScrollView中使用RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文