重写EditText的onTouchEvent方法

1
2
3
4
5
6
7
8
9
10
@Override
public boolean onTouchEvent(MotionEvent event) {
//解决EditText嵌套到ScrollView中时不能滚动的问题
if(event.getAction()==MotionEvent.ACTION_DOWN){
this.getParent().requestDisallowInterceptTouchEvent(true);
} else if(event.getAction() == MotionEvent.ACTION_UP){
this.getParent().requestDisallowInterceptTouchEvent(false);
}
return super.onTouchEvent(event);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mGoodsDesEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (view.getId() ==R.id.goods_des) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});