我有一个自定义的 Scrollview,HorizontalScrollview,里面是一个动态表。表格中的每一行都有多个带有 onclicklisteners 的 TextView。
如果我在 Y 方向上滑动,然后点击屏幕一次,就会出现问题。垂直滚动(滚动视图)将停止工作,但水平滚动仍然有效。请赐教。
滚动视图:
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);
}
}
感谢您的任何建议。