我的应用程序的设计
屏幕-1
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout>(contains Recyclerview-2)
</NestedScroll>屏幕-2
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout> (fragment changed, contains Recyclerview-3)
</NestedScroll>现在,如果用户在屏幕1上,那么两个回收视图将同时滚动,但在屏幕2上,如果用户滚动RV1,则只有RV1将滚动。如果滚动RV3,则将滚动RV3。尝试了所有类型的停止滚动,但无法停止滚动嵌套滚动视图。
发布于 2019-02-28 01:32:34
您必须创建一个不对触摸和滚动事件执行任何操作的新类:
public class LockableNestedScrollView extends NestedScrollView {
// by default is scrollable
private boolean scrollable = true;
public LockableNestedScrollView(@NonNull Context context) {
super(context);
}
public LockableNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public LockableNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return scrollable && super.onTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return scrollable && super.onInterceptTouchEvent(ev);
}
public void setScrollingEnabled(boolean enabled) {
scrollable = enabled;
}
}接下来,在您的布局中,通过新类更改NestedScroll:
<your.package.name.path.LockableNestedScrollView>
<LinearLayout
orientation:"horizontal"
android:id="@+id/scroll_name">
<RecyclerView-1>
<Framelayout>(contains Recyclerview-2)
</your.package.name.path.LockableNestedScrollView>最后,在你的活动中:
LockableNestedScrollView myScrollView = (LockableNestedScrollView) findViewById(R.id.scroll_name);
myScrollView.setScrollingEnabled(false);我希望它能帮助其他人。
https://stackoverflow.com/questions/50770993
复制相似问题