package cn.benben.hoola.untils; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.ViewConfiguration; import android.widget.ScrollView; /** * Created by caojieting on 2018/10/13. * * 解决嵌套recycle滑动卡顿 */ public class TopicScrollView extends ScrollView { private int downX; private int downY; private int mTouchSlop; public TopicScrollView(Context context) { super(context); mTouchSlop= ViewConfiguration.get(context).getScaledTouchSlop(); } public TopicScrollView(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop= ViewConfiguration.get(context).getScaledTouchSlop(); } public TopicScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTouchSlop= ViewConfiguration.get(context).getScaledTouchSlop(); } @Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Log.e("eee","按下了"); requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: // Log.e("eee","抬起了"); requestDisallowInterceptTouchEvent(false); break; case MotionEvent.ACTION_CANCEL: // Log.e("eee","CANCEL取消了"); requestDisallowInterceptTouchEvent(false); break; } return super.onTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent e) { int action = e.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: downX = (int) e.getRawX(); downY = (int) e.getRawY(); break; case MotionEvent.ACTION_MOVE: int moveY = (int) e.getRawY(); if (Math.abs(moveY - downY) > mTouchSlop) { requestDisallowInterceptTouchEvent(true); return true; } } return super.onInterceptTouchEvent(e); } } ps:另外一种方法 参考:
https://blog.youkuaiyun.com/qq_40848783/article/details/80068735ScrollView嵌套recycle滑动卡顿
//解决滑动冲突、滑动不流畅 recyclerMagicView.setHasFixedSize(true); recyclerMagicView.setNestedScrollingEnabled(false);
ScrollView嵌套recycle滑动卡顿
最新推荐文章于 2024-10-11 18:28:35 发布