Fade effect between layouts

前端 未结 3 1298
离开以前
离开以前 2021-02-04 13:21

As by object, I would reproduce fade effect between two layout. Now I\'ve this situation:

LinearLayout l;
LinearLayout l2;

To switch between th

3条回答
  •  感动是毒
    2021-02-04 13:55

    Using R.anim.fade_out & .R.anim.fade_in you can create an animation which does this. I don't know much about this myself but heres a tutorial regarding animations in android: Animation Tutorial

    P.S. This tutorial is not mine thus credit does not go out to me.

    Edit:

    AnimationSet set = new AnimationSet(true);
    
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);
    
    animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
    );
    animation.setDuration(100);
    set.addAnimation(animation);
    
    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    l.setLayoutAnimation(controller);
    

    Fade out Animation

    public static Animation runFadeOutAnimationOn(Activity ctx, View target) {
      Animation animation = AnimationUtils.loadAnimation(ctx,android.R.anim.fade_out);
      target.startAnimation(animation);
      return animation;
    }
    

    I'm guessing you can try something like this, I copy pasted the animation from the tutorial I don't know what it does exactly as I have no experience with Android development. Another example could be Example 2

提交回复
热议问题