2

我需要垂直制作这个动画ViewPager

在此处输入图像描述

https://www.youtube.com/watch?v=wuE-4jjnp3g

这是我到目前为止所尝试的:

   viewPager = (VerticalViewPager) rootView.findViewById(R.id.viewpager);

   viewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
        @Override
        public void transformPage(View page, float position) {

            if (position >= 0.5F && position <= 1F) {

                float progressStart = 0.5f;
                float progressEnd = 1f;
                float progressDelta = progressEnd - progressStart;

                float progress = (position - progressStart)/progressDelta;
                if(progress>1)progress=1;
                if(progress<0)progress=0;

                float endValue = 1f;
                float startValue = 0.8f;

                float delta = endValue - startValue;

                progress = 1-progress;
                float currentScale = startValue + delta*progress;

                ViewCompat.setPivotY(page,0);
                ViewCompat.setScaleX(page, currentScale);
                ViewCompat.setScaleY(page, 0.9F);
                ViewCompat.setTranslationY(page, 0);

            } else {
                ViewCompat.setScaleX(page, 1.0F); //- width
                ViewCompat.setScaleY(page, 0.9F); //- height
            }

        }
    });

这是结果:

在此处输入图像描述

https://www.youtube.com/watch?v=G9W2lCKP-_s

我正在使用垂直方向的原始 ViewPager 的副本来查看代码:https://github.com/Devlight/InfiniteCycleViewPager/blob/master/infinitecycleviewpager/src/main/java/com/gigamole/infinitecycleviewpager/VerticalViewPager。爪哇

显然它甚至没有关闭,我需要预览下一页并使两页更接近。

在此处输入图像描述

请帮忙

谢谢你。

4

1 回答 1

2

我需要预览下一页

你必须添加

        android:paddingBottom="200dp"
        android:clipToPadding="false"

到你<com.gigamole.infinitecycleviewpager.VerticalViewPager的布局

在你的java代码中放它,当然你应该在你的布局中调整startTranslationstartValuepaddingBottom

        viewPager.setPageTransformer(true, new ViewPager.PageTransformer() {
        @Override
        public void transformPage(View page, float position) {
            ViewCompat.setPivotY(page,0);
            ViewCompat.setPivotX(page,page.getWidth()/2);
            float endTranslation = 0f;
            float startTranslation  = -400f;
            float deltaTranslation = endTranslation - startTranslation;

            float endScale = 1f;
            float startScale = 0.8f;
            float deltaScale = endScale - startScale;
            
            float progressStart = 0.5f;
            float progressEnd = 1f;
            float progressDelta = progressEnd - progressStart;

            float progress = (position - progressStart)/progressDelta;
            if(progress>1)progress=1;
            if(progress<0)progress=0;

            progress = 1-progress;
            
            float currentScale = startScale + deltaScale*progress;
            ViewCompat.setScaleX(page, currentScale);
            ViewCompat.setScaleY(page, currentScale);

            float currentTranslation = startTranslation + deltaTranslation*progress;
            ViewCompat.setTranslationY(page, currentTranslation);
        }
于 2017-05-29T15:16:49.970 回答