简体   繁体   中英

How to modify this Horizontal ViewPager transformer into Vertical transformer?

this is the code I have.It works fine for Horizontal transformation animation. I want to transform my ViewPager transition animation vertically.

public class AccordionPageTransformer implements ViewPager.PageTransformer {
@Override
public void transformPage(View page, float position) {
    // Counteract the default slide transition
    page.setTranslationX(-position * page.getWidth());

    page.setPivotX(position < 0 ? 0 : page.getWidth());
    page.setScaleX(1 - Math.abs(position));
}}

Try this for ViewPager,

        if (position < -1) { 
            page.setAlpha(0);

        } else if (position <= 1) { 
            page.setAlpha(1);

            // Counteract the default slide transition
            page.setTranslationX(page.getWidth() * -position);

            //Set Y position to swipe in from top
            float yPosition = position * page.getHeight();
            page.setTranslationY(yPosition);

        } else { 
            page.setAlpha(0);
        }

Or you can also use ViewPager2 It provides single line code to make scrolling vertical,

myViewPager2.setOrientation(ViewPager2.ORIENTATION_VERTICAL); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM