Android:flipper 视图未翻转
基本上,我有一个 ViewFlipper,当我在上面滑动手指时它会翻转。这是我在 Activity 中的代码:
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (oldTouchValue > currentX) {
ViewHelper.swapFlipperNext(vf);//helper method for flipping
setMyProgress();//helper method to set my progress bar
}
if (oldTouchValue < currentX) {
ViewHelper.swapFlipperPrevious(vf);
setMyProgress();
}
break;
}
}
return false;
}
它工作得很好,除了一件事,如果我的手指位于屏幕的非视图部分,我可以翻转它。但是,如果我的人物在某些视图上滑动(因为我的翻转器的每个页面中也有文本视图和网页视图),则 onTouchEvent 不会被激活,因此 ViewFlipper 不会被切换,我该如何解决这个问题?多谢
Basically, I have a ViewFlipper that flips when I swipe my finger on it. This is the code I have in my Activity:
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (oldTouchValue > currentX) {
ViewHelper.swapFlipperNext(vf);//helper method for flipping
setMyProgress();//helper method to set my progress bar
}
if (oldTouchValue < currentX) {
ViewHelper.swapFlipperPrevious(vf);
setMyProgress();
}
break;
}
}
return false;
}
It works perfectly except for one thing, I can flip it if my finger is on a non-view part of the screen. But if my figure swipe on some views(Since I have textviews and webviews in each page of the flipper too), the onTouchEvent doesn't get activated, so the ViewFlipper doesn't get switched, how do I fix that? Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 textview 和 webview 上的 focusable 属性设置为 false。基本上我认为正在发生的是这些正在消耗触摸事件。
编辑:如果这不起作用,请尝试以下操作
,其中gestureDetector是成员变量。
从这里查看: EditText 未捕获 ViewFlipper flings?
try setting the focusable attribute on your textviews and webviews to false. basically what i think is happening is these are consuming the touch event.
EDIT: if this doesn't work, try the following
where gestureDetector is a member variable.
see from here: EditText not capturing ViewFlipper flings?