1
我有一個自定義Scrollview,HorizontalScrollview,裏面是一個動態表。表中的每一行都有多個帶有onclicklistener的TextView。ScrollView停止工作後滾動+水龍頭
如果我在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);
}
}
感謝您的任何意見。
不相信解決方案那麼簡單。 – wtsang02