![](/img/trans.png)
[英]How to disable RecyclerView scrolling to make the layout listen its ScrollView parent?
[英]How to disable child(RecyclerView) scrolling before parent(ScrollView) has completely scrolled
我在ScrollView中有一个RecyclerView。 当我尝试滚动到底部时,在父级开始滚动之前,RecyclerView(子元素)会滚动到底部。 但是我想要的是,在孩子开始滚动之前,父母应该完全滚动。 这是我的布局文件。 有人可以指导我如何实现这一目标吗?
<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>
禁用RecyclerView。 扩展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);
}
}
一旦您的scrollViewReaches底部启用recyclerView。 搏一搏。 如果您无法使用此方法实现您的期望,请告诉我。
只需使用NestedScrollView-它支持在其中启用嵌套滚动启用的视图(例如RecyclerView
)。 确保您使用的是Support Library 23.2 ,该库允许RecyclerView
根据其内容对其自身进行度量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.