短视频商城源码,滑动时渐变效果实现

2020-09-30 15:26:47 浏览数 (1)

代码语言:javascript复制

      viewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
           @Override
           public void transformPage(@NonNull View view, float position) {
               float alpha = 0.0f;
               if (0.0f <= position && position <= 1.0f) {
                   alpha = 1.0f - position;
               } else if (-1.0f <= position && position < 0.0f) {
                   alpha = position   1.0f;
               }
               view.setAlpha(alpha);
           }
       });

0 人点赞