How to create a carousel using viewpager and fragmentStatePager Adapter

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 20:57:02

For anyone else who comes across this, I used this code to achieve a pretty nice effect.

pager.setPageMargin((int) (getResources().getDisplayMetrics().widthPixels * -0.33));
pager.setOffscreenPageLimit(5);
pager.setPageTransformer(false, new ViewPager.PageTransformer() {
    @Override public void transformPage(View page, float position) {
        page.setScaleX(0.7f - Math.abs(position * 0.4f));
        page.setScaleY(0.8f - Math.abs(position * 0.6f));
        page.setAlpha(1.0f - Math.abs(position * 0.5f));
    }
});

You can take help from Gamma Developer guide to make a carousel.

Here is the link

Hey not sure whether it is a proper solution or not but i just added one line

 pager.setPageMargin(getResources().getDisplayMetrics().widthPixels /-7);

and now my view shows a portion of the left and right fragments also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!