
我的应用程序的设计
屏幕 – 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上,那么recyclelervIEw将同时滚动,但是如果用户滚动RV1,则在屏幕2上,如果RV3滚动,则RV1将同样滚动,然后滚动RV3.尝试了所有类型的停止滚动,但无法停止嵌套滚动视图的滚动.
解决方法:
您必须创建一个在触摸和滚动事件时不执行任何 *** 作的新类:
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);我希望它可以帮助别人.
总结以上是内存溢出为你收集整理的android – 禁用NestedScrollview滚动全部内容,希望文章能够帮你解决android – 禁用NestedScrollview滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)