我们在处理自定义View时候,会重写dispatchTouchEvent方法,但是在有些时候,只能获得ACTION_DOWN,不能获得ACTION_MOVE
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.e(TAG, "dispatchTouchEvent: " + ev.toString());
return super.dispatchTouchEvent(ev);
}
解决方法:
在目标控件(view)的布局中,添加属性:android:clickable="true"
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
就可以获得ACTION_MOVE事件了