EditText 没有捕获 ViewFlipper 的滑动?
这太令人抓狂了。我有以下 XML 布局:
<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:
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 背景设置为“红色”,并注意到该红色矩形内没有任何内容可以激活快速滑动。那么我该如何进行这项工作呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重写活动的dispatchTouchEvent方法:
显然,gestureDetector是您需要在活动上声明和初始化的成员变量。
You may override activity's dispatchTouchEvent method:
Obviously gestureDetector is a member variable you need to declare and initialize on your activity.
尝试为
ViewFlipper
应用setLongClickable(true)
try to apply
setLongClickable(true)
for theViewFlipper