我有一个自定义Scrollview,HorizontalScrollview,而inside是一个动态表。表中的每一行都有多个带onclicklisteners的TextView。
如果我沿Y方向滑动,然后点击屏幕一次,则会出现问题。垂直滚动(ScrollView)将停止工作,但水平滚动仍然有效。请赐教。
滚动型:
public class ParentScrollView extends ScrollView {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
@SuppressWarnings("deprecation")
public ParentScrollView(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;
}
}
}
TableRowView和textview:
public void addRow(String[] data, int[] rowId) {
for (int i = 0; i < data.length; i++) {
TextView tv = parseTextView(data[i]);
tv.setId(rowId[i]);
tv.setFocusable(false);//try solving with this, no luck.
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(ChooseTableActivity.class == (v.getContext().getClass())){
((ChooseTableActivity) v.getContext())
.onClickRowCell(v);
//passes view to activiy class that does nothing yet.
}
}
});
this.addView(tv);
}
}
感谢您的任何建议。
答案 0 :(得分:1)
你的onInterceptTouchEvent可能存在问题。如果它重新出现错误,则不会触发所有其他事件(移动,取消和向上)。尝试更换 super.onInterceptTouchEvent(ev)&amp;&amp; mGestureDetector.onTouchEvent(EV) 同 super.onInterceptTouchEvent(ev)|| mGestureDetector.onTouchEvent(EV)