Skip to content

Instantly share code, notes, and snippets.

@Ajith-Pandian
Created December 23, 2016 11:26
Show Gist options
  • Save Ajith-Pandian/cbc07f1ce9aa9e9048e3ba16f9cb4407 to your computer and use it in GitHub Desktop.
Save Ajith-Pandian/cbc07f1ce9aa9e9048e3ba16f9cb4407 to your computer and use it in GitHub Desktop.
Custom View Pager
public class MyViewPager extends ViewPager {
public MyViewPager(Context context) {
this(context, null);
}
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
setPageTransformer(false, new DefaultTransformer());
}
private MotionEvent swapTouchEvent(MotionEvent event) {
float width = getWidth();
float height = getHeight();
float swappedX = (event.getY() / height) * width;
float swappedY = (event.getX() / width) * height;
event.setLocation(swappedX, swappedY);
return event;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
swapTouchEvent(ev);
return super.dispatchTouchEvent(ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment