J'ai quelques vues dans ScrollView. Le problème est que lorsque je touche la vue enfant et que je la fais défiler verticalement, la vue enfant ne peut recevoir que les événements ACTION_DOWN
et ACTION_CANCEL
. L'événement ACTION_MOVE
et ACTION_UP
est manqué.
Si je touche la vue enfant et la fais défiler horizontalement, la vue enfant peut obtenir tous les événements tactiles comme prévu.
Voici mon code:
fichier xml:L'enfant de ScrollView ne peut pas recevoir les événements ACTION_MOVE et ACTION_UP lorsque vous touchez l'enfant et faites défiler verticalement
<?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>
code java:
@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;
}
Tout le monde peut me aider Merci beaucoup?.
Merci beaucoup. Cela vient résoudre mon problème! – hanswim