我把一个HorizontalListView放在一个ScrollView里面,当在Horizontal上水平滑动的时候可以滑动HorizontalListView,但是当在HorizontalListView上垂直滑动的时候并不能使ScrollView发生垂直方向上的滑动,应该怎么解决?如果HorizontalListVIew垂直方向的尺寸不大还好,影响不大,但是如果HorizontalListView的高度比较大的话,就太影响使用了
HorizontalListView影响了ScrollView在垂直方向 的滑动,求大神帮忙
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- 简一_hz 2016-02-24 01:27关注
自定义一个ScrollView
public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;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) { if(Math.abs(distanceY) > Math.abs(distanceX)) { return true; } return false; } }
}
解决 无用评论 打赏 举报