Created
December 23, 2016 11:26
-
-
Save Ajith-Pandian/cbc07f1ce9aa9e9048e3ba16f9cb4407 to your computer and use it in GitHub Desktop.
Custom View Pager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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