当前位置: 代码迷 >> Android >> 【转】android中scrollview嵌套HorizontalScrollView招致横向滑动卡顿现象解决
  详细解决方案

【转】android中scrollview嵌套HorizontalScrollView招致横向滑动卡顿现象解决

热度:71   发布时间:2016-05-01 12:57:10.0
【转】android中scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决

转载自:IT驿站[http://www.blogchen.com]

本文链接: http://www.blogchen.com/archives/584.html

?

也许会有人遇到,在这里说下解决方法。方便以后有人纠结这个问题。

开发中经验会遇到滑动里面嵌入滑动的问题,但是这种情况下触摸事件就会发生冲突。导致滑动非常卡,甚至出现程序停止响应。这种情况下我们一般需要重写view。下面给出重新scrollview的方法:

?

public class CustomScrollView extends ScrollView {    private GestureDetector mGestureDetector;    View.OnTouchListener mGestureListener;         @SuppressWarnings("deprecation")    public CustomScrollView(Context context, AttributeSet attrs) {        super(context, attrs);        mGestureDetector = new GestureDetector(new YScrollDetector());        setFadingEdgeLength(0);     }    @Override    public boolean onInterceptTouchEvent(MotionEvent ev) {        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);     }    // Return false if we're scrolling in the x direction    class YScrollDetector extends SimpleOnGestureListener {        @Override        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {            if (Math.abs(distanceY) > Math.abs(distanceX)) {                return true;            }            return false;        }    }}
?
  相关解决方案