本文主要是介绍Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
直接上代码 我这个scrollview因为业务需求做了滑动监听 解决惯性问题只需在onInterceptTouchEvent(MotionEvent e)方法里做处理就行 别的不需要考虑 简单 暴力
/*** 带滚动监听的Scrollview* 用于随着Scrollview的滑动更改状态栏的透明度*/
public class MyScrollview extends ScrollView {private int downX;private int downY;private int mTouchSlop;private ScrollViewListener scrollViewListener = null;public MyScrollview(Context context) {super(context);}public MyScrollview(Context context, AttributeSet attrs) {super(context, attrs);}public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}public void setScrollViewListener(ScrollViewListener scrollViewListener) {this.scrollViewListener = scrollViewListener;}@Overrideprotected void onScrollChanged(int l, int t, int oldl, int oldt) {super.onScrollChanged(l, t, oldl, oldt);if (scrollViewListener != null) {scrollViewListener.onScrollChanged(this, l, t, oldl, oldt);}}public interface ScrollViewListener {void onScrollChanged(MyScrollview scrollView, int l, int t, int oldl, int oldt);}/*** 屏蔽内部recyclerview的滑动事件* @param e* @return*/@Overridepublic 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) {return true;}}return super.onInterceptTouchEvent(e);}
}
这篇关于Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!