EditText上没有捕捉ViewFlipper甩?EditText、ViewFlipper

2023-09-13 01:40:34 作者:き执迷不悟れ

这是郁闷。我有以下的XML布局:

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>

和Java:

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;
        }
    };

好像如果我尝试一扔上的EditText区域的上方,手势不注册。不过,如果我扔的围绕的它,也就是的EditText的背景下,它的工作。我试着跟随周围的FILL_PARENT / WRAP_CONTENT的高度和宽度,但它似乎并没有改变任何事情。我已经证实了这一怀疑我制作的EditText背景的红,并指出,该红色矩形内没有任何东西可以激活一个一扔。那么,如何使这项工作?

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?

推荐答案

您可以覆盖活动的dispatchTouchEvent方式:

You may override activity's dispatchTouchEvent method:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (gestureDetector != null) {
        gestureDetector.onTouchEvent(ev);
    }
    return super.dispatchTouchEvent(ev);
}

显然gestureDetector是你需要声明和初始化您的活动的一个成员变量。

Obviously gestureDetector is a member variable you need to declare and initialize on your activity.