分析京东“搜索京东商品/店铺”布局(二)

时间:2021-12-08 08:15:52

接着前面一篇文章,ScrollView嵌套了HorizontalScrollView和ListView,

这里如何处理ScrollView和HorizontalScrollView冲突的问题呢?


Android - HorizontalScrollView within ScrollView Touch Handling

http://*.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling?lq=1

public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;

public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, 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) {
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}

这样子实现就可以了。