我在我的应用程序中使用 Viewpager.. 当用户向左或向右滑动时,我将显示下一张或上一张图像 - 基本上是幻灯片(图像)类型的应用程序..
如果用户点击应用程序,我想在 ViewPager 中翻转视图。每个视图后面的视图 - 用户必须能够在点击视图时翻转视图。
这是代码,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
.... <some code> ....
viewPager = (ViewPager) findViewById(R.id.main_viewpager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
PageListener pageListener = new PageListener();
viewPager.setOnPageChangeListener((OnPageChangeListener) pageListener);
final GestureDetector tapGestureDetector = new GestureDetector(this, new TapGestureListener());
viewPager.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
tapGestureDetector.onTouchEvent(event);
return false;
}
});
}
private class TapGestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// HERE I CAPTURED SINGLE TAP.. HOW DO I CHANGE THE VIEW OF VIEWPAGER?
return false;
}
}