问题
This is maddening. I have the following XML layout:
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shadow" android:focusable="true" android:focusableInTouchMode="true">
<ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent">
<EditText android:id="@+id/reviews" style="@style/DescriptionArea" android:layout_width="fill_parent" android:layout_height="wrap_content" android:enabled="false" android:background="@null" />
<EditText android:id="@+id/notes" style="@style/DescriptionArea" android:hint="@string/detail_hint" android:layout_width="fill_parent" android:layout_height="wrap_content" android:enabled="false" android:maxLines="4"/>
</ViewFlipper>
</FrameLayout>
And the Java:
viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
It seems like if I try to fling on top of the EditText area, the gesture does not register. However, if I fling around it, that is, the background of the EditText, it DOES work. I've tried following around with the fill_parent/wrap_content heights and widths, but it doesn't seem to change a thing. I've confirmed this suspicion my making the EditText background "red," and noting that nothing within that red rectangle can activate a fling. So how do I make this work?
回答1:
You may override activity's dispatchTouchEvent method:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (gestureDetector != null) {
gestureDetector.onTouchEvent(ev);
}
return super.dispatchTouchEvent(ev);
}
Obviously gestureDetector is a member variable you need to declare and initialize on your activity.
回答2:
try to apply setLongClickable(true)
for the ViewFlipper
来源:https://stackoverflow.com/questions/3542065/edittext-not-capturing-viewflipper-flings