通过创建NestedScrollView,您可以将滚动视图放在另一个滚动视图中,只要这些视图正确实现NestedScrollingChild和NestedScrollingParent.
(这是一个不错的设计模式"Ian Lake(来自Google)实际上建议在RecyclerView这里放置一个nestedscrollview:plus.google.com/u/0/+AndroidDevelopers/posts/9kZ3SsXdT2T")
我想将RecyclerView放在NestedScrollView中,幸运的是RecyclerView实现了NestedScrollingChild,因此您可以将它放在NestedScrollView中.
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild
Run Code Online (Sandbox Code Playgroud)
我看过这些帖子:
如何在NestedScrollView中使用RecyclerView?
NestedScroll与NestedScrollView,RecyclerView(水平),在CoordinatorLayout内
但是大多数投票解决方案的问题是,它调用所有项目,RecyclerView例如,如果它是无尽的RecyclerView,当用户到达列表的末尾时,您想要发出网络请求,然后使用该解决方案RecyclerView重复调用服务器因为它会自动到达最后一项RecyclerView.
无论如何,如何设置参数,以便我可以放入RecyclerView内部NestedScrollView.(实际上我想将一个像framelayout或relativelayout这样的视图组作为nestedscrollview的单个childe然后我想将recyclelerview放在framelayout或relativelayout中)
当我放在RecyclerView里面NestedScrollView没有什么可以显示.
要创建示例项目,您可以使用cheesesquare并更改CheeseDetailActivity为具有RecyclerView.
虽然BNK的答案不正确,但BNK已经尝试了很多.所以我授予他赏金.还在寻找好的解决方案....
我有这个布局:
<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>
Run Code Online (Sandbox Code Playgroud)
它运作良好.我可以RecyclerView平滑滚动而无需滚动父视图.
现在我必须把RecyclerView内部放在这样一个FrameLayout:
<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>
Run Code Online (Sandbox Code Playgroud)
现在我无法RecyclerView顺利滚动.我想要的是:RecyclerView平滑滚动而不滚动父视图.我该怎么办?
编辑:这是我的review_empty布局:
<?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" …Run Code Online (Sandbox Code Playgroud)