如何同时淡出/进入和Slideleft / SlideRight动画

时间:2015-05-07 09:45:23

标签: android android-animation

我正在尝试同时滑动和淡出动画导航,同时导航到下一页。

为了淡出,我使用的是Code。

    ObjectAnimator fadeOut = ObjectAnimator.ofFloat(layoutanim, "alpha",
            1f, .3f);
    fadeOut.setDuration(5000);

对于Sliding,我使用动画

获取代码
public Animation inFromRightAnimation() {

    Animation inFromRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, +1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromRight.setDuration(500);
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
}

我正在尝试使用animator set一起玩。但它正在使用动画进行幻灯片效果。如何将inFromRightAnimation()从动画转换为动画师以一起播放。或者其他方法是使用Object Animator实现inFromRight。

1 个答案:

答案 0 :(得分:0)

尝试AnimationSet

Animation fade = new AlphaAnimation(1f, .3f);
fade.setDuration(5000);
Animation inFromRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, +1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(inFromRight);
animationSet.addAnimation(fade);
layoutanim.setAnimation(animationSet);