All the fragment is gone when used DepthPageTransformer

故事扮演 提交于 2020-01-04 05:46:12

问题


There is a view pager, and used the DepthPageTransformer .

mViewPager.setPageTransformer(false, new DepthPageTransformer());

The DepthPageTransformer code:

public class DepthPageTransformer implements PageTransformer {
    private static float MIN_SCALE = 0.5f;


    @Override
    public void transformPage(View view, float position) {
        /**
         * [-1,0]Use the default slide transition when moving to the left page
         * (0,1] Use the default slide transition when moving to the right page
         * (1,+Infinity] This page is way off-screen to the right.
         * [-Infinity,-1) This page is way off-screen to the left.
         */

        int pageWidth = view.getWidth();

        if (position > 1){
            view.setAlpha(0);
            view.setTranslationX(0);
        }
        else if (position > 0){
            view.setAlpha(1);
            view.setTranslationX(0);
            view.setScaleX(1);
            view.setScaleY(1);
        }
        else if (position >= -1){
            view.setAlpha(1);

            view.setTranslationX(pageWidth * -position);
            // Scale the page down (between MIN_SCALE and 1)
            float scaleFactor = MIN_SCALE + (1 - MIN_SCALE)
                    * (1 - Math.abs(position));
            view.setScaleX(scaleFactor);
            view.setScaleY(scaleFactor);
        }
        else{
            view.setAlpha(0);
            view.setScaleX(1);
            view.setScaleY(1);
        }
    }
}

Somethings it will happen when scroll the view pager: all the fragment is gone. Or the only back fragment is shown, and the scale is 0.5, but the front fragment is gone, so we can see a small fragment in the screen.

来源:https://stackoverflow.com/questions/33560721/all-the-fragment-is-gone-when-used-depthpagetransformer

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