Android: fllipper view not getting flliped
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开发者_StackOverflow社区 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
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
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (gestureDetector != null) {
gestureDetector.onTouchEvent(ev);
}
return super.dispatchTouchEvent(ev);
}
where gestureDetector is a member variable.
see from here: EditText not capturing ViewFlipper flings?
精彩评论