ViewPager animation fade in/out instead of slide

后端 未结 5 574
心在旅途
心在旅途 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:51

    This should work better for the fade in/out transform:

    public void transformPage(View view, float position) {
        view.setTranslationX(view.getWidth() * -position);
           
        if(position <= -1.0F || position >= 1.0F) {
            view.setAlpha(0.0F);
        } else if( position == 0.0F ) {
            view.setAlpha(1.0F);
        } else { 
            // position is between -1.0F & 0.0F OR 0.0F & 1.0F
            view.setAlpha(1.0F - Math.abs(position));
        }
    }
    

提交回复
热议问题