ViewPager animation fade in/out instead of slide

后端 未结 5 575
心在旅途
心在旅途 2020-12-23 20:27

I got the FragmentBasics example from here. Is there a way make the ViewPager animation simply fade in and out when I swipe instead of sliding left and right? I\'ve been try

5条回答
  •  一个人的身影
    2020-12-23 20:42

    Fade according to Google: https://developer.android.com/training/animation/reveal-or-hide-view

    viewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
        @Override
        public void transformPage(@NonNull View page, float position) {
            page.setAlpha(0f);
            page.setVisibility(View.VISIBLE);
    
            // Start Animation for a short period of time
            page.animate()
                .alpha(1f)
                .setDuration(page.getResources().getInteger(android.R.integer.config_shortAnimTime));
        }
    });
    

提交回复
热议问题