我使用以下翻转图片的方法:How to set dymanic images to ViewFlipper in android?
我不想使用按钮翻转。当用户触摸图像或滑动图像时,我想翻转到下一个图像。有没有办法实现这个目标?
答案 0 :(得分:2)
您可以使用ViewPager。请参阅以下链接:
Implementing Horizontal View Swiping Using ViewPager and FragmentPagerAdapter in Android
Horizontal View Swiping with ViewPager, Updated
Android Viewpager as Image Slide Gallery (Swipe Gallery)
和本图书馆
答案 1 :(得分:0)
这可能有帮助..... animator是res中的文件夹,而s_out_ * 是带有翻译的xml文件
public boolean onTouchEvent(MotionEvent touchevent){
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (viewFlipper.getDisplayedChild() == 0)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fleft);
viewFlipper.setOutAnimation(this, R.animator.s_out_right);
viewFlipper.showNext();
}
if (lastX > currentX) {
if (viewFlipper.getDisplayedChild() == 1)
break;
viewFlipper.setInAnimation(this, R.animator.s_in_fright);
viewFlipper.setOutAnimation(this, R.animator.s_out_left);
viewFlipper.showPrevious();
}
break;
}
}
return false;
}