EditText not capturing ViewFlipper flings?

試著忘記壹切 提交于 2020-01-11 06:21:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!