简体   繁体   中英

Change fragment dimensions when selected in viewpager

Is there a way to increase the size of the current fragment and then reducing it back when its not selected in a ViewPager?

在此处输入图片说明

在此处输入图片说明

What you are looking for is ViewPager.PageTransformer .

With a PageTransformer , you can zoom the View as it is being swiped into view.

Here's an example of one that will zoom the way you want. Try this to start:

    public static class PageTransformer implements ViewPager.PageTransformer {
        @Override
        public void transformPage(View page, float position) {

            // this part changes the scale, which is the zoom part
            page.setScaleX(1.0F - .33F * Math.abs(position));
            page.setScaleY(1.0F - .33F * Math.abs(position));

            // this part sets up so the page zooms from the center
            page.setPivotX(page.getWidth() / 2.0F);
            page.setPivotY(page.getHeight() / 2.0F);
        }
    }

To set it up:

        viewPager.setPageTransformer(false, new PageTransformer());

Customize the Animation with PageTransformer | Android Developers

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