English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
ViewPager has a method called:
setPageTransformer(boolean reverseDrawingOrder, PageTransformer transformer)
Used to set the animation effect when switching ViewPager.
Here we just need to customize a PageTransformer to achieve the animation offset effect we need!
public class ScrollOffsetTransformer implements PageTransformer { private static final float MIN_SCALE = 0.85F; /** * The position parameter indicates the position of the given page relative to the center of the screen. It is a dynamic property that changes as the page scrolls. * When a page (page) fills the entire screen, the positoin value is 0; when a page (page) just leaves the right (left) side of the screen, the position value is1(-1); * When both pages have scrolled halfway, one of the pages is-0.5, the other page is 0.5. * Based on the position of the page on the screen, through methods such as setAlpha(), setTranslationX * use methods like setScaleY() to set the properties of the page, creating a custom sliding animation. */ @Override public void transformPage(View view, float position) { // TODO Auto-generated method stub float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); float rotate = 30 * Math.abs(position); float transla = 50 * Math.abs(position); if (position > 0) { view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); view.setRotationY(-rotate); view.setTranslationX(-transla); } else { view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); view.setRotationY(rotate); view.setTranslationX(transla); } } }
then
viewPager
plus
viewPager.setPageTransformer(true, new ScrollOffsetTransformer())
The above is what the editor introduces to everyone about Android viewpager 3The implementation method of D gallery, hoping it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. I also want to express my sincere gratitude to everyone for their support of the Yana Tutorial website!
Statement: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.