I have some views in ScrollView. The problem is when I touch the child view and scroll it vertically, the child view can only get ACTION_DOWN
and ACTION_CANCEL
event. The ACTION_MOVE
and ACTION_UP
event is missed.
If I touch the child view and scroll it horizontally, the child view can get all the touch event just as expected.
Here is my code:
xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/sv_test_tv"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="This is some text."
android:textSize="30sp" />
<View
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#faa" />
<View
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#faf" />
</LinearLayout>
</ScrollView>
java code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sv_test);
TextView tv = (TextView) findViewById(R.id.sv_test_tv);
tv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
LogUtils.v("ScrollViewTest", "onTouch:" + getType(event.getAction()));
return true;
}
});
}
private String getType(int type) {
switch (type) {
case MotionEvent.ACTION_DOWN: {
return "ACTION_DOWN";
}
case MotionEvent.ACTION_MOVE: {
return "ACTION_MOVE";
}
case MotionEvent.ACTION_UP: {
return "ACTION_UP";
}
}
return "other:" + type;
}
Anyone can help me? Thanks a lot.