[英]How to disable child(RecyclerView) scrolling before parent(ScrollView) has completely scrolled
I have a RecyclerView inside a ScrollView. 我在ScrollView中有一个RecyclerView。 When I try to scroll to bottom, the RecyclerView(child element) scrolls to bottom before the parent starts scrolling.
当我尝试滚动到底部时,在父级开始滚动之前,RecyclerView(子元素)会滚动到底部。 But what I want it, the parent should scroll completely before child starts scrolling.
但是我想要的是,在孩子开始滚动之前,父母应该完全滚动。 Here is my layout file.
这是我的布局文件。 Can someone please guide me how can I achieve this?
有人可以指导我如何实现这一目标吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/user_activity_linear_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/blank_layout"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recently_watched_recycler_view"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/blank_layout"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Disable RecyclerView. 禁用RecyclerView。 Extend scrollview so that you will know when ot has reached bottom as bellow.
扩展scrollview,以便您可以知道ot何时到达底部。
public class myScrollView extends ScrollView
{
public myScrollView(Context context)
{
super(context);
}
public myScrollView(Context context, AttributeSet attributeSet)
{
super(context,attributeSet);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
View view = (View)getChildAt(getChildCount()-1);
int d = view.getBottom();
d -= (getHeight()+getScrollY());
if(d==0)
{
//you are at the end of the list in scrollview
//do what you wanna do here
}
else
super.onScrollChanged(l,t,oldl,oldt);
}
} }
Once your scrollViewReaches bottom enable recyclerView. 一旦您的scrollViewReaches底部启用recyclerView。 Give it a go.
搏一搏。 If you are not able to achieve what you desire using this method let me know.
如果您无法使用此方法实现您的期望,请告诉我。
Just use NestedScrollView - it supports having nested scrolling enabled views (such as RecyclerView
) inside of it. 只需使用NestedScrollView-它支持在其中启用嵌套滚动启用的视图(例如
RecyclerView
)。 Make sure you are using Support Library 23.2 , which allows RecyclerView
to measure itself based on its contents. 确保您使用的是Support Library 23.2 ,该库允许
RecyclerView
根据其内容对其自身进行度量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.