gpt4 book ai didi

安卓链动画

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:59:33 25 4
gpt4 key购买 nike

我正在尝试将两个动画“链接”在一起,因此当一个完成时,另一个开始。除了一个问题外,这是有效的。第一个动画完成后,它会回到原来的位置。我将 fill after 设置为 true。我还缺少什么?

这是我使用的代码。请注意,这是在扩展 LinearLayout 的类中。

// FIRST ANIMATION
mAnimation = new TranslateAnimation(0, PANEL_END_X, 0, 0);
mAnimation.setDuration(PANEL_TRANSITION_TIME);
mAnimation.setFillAfter(true);

mAnimation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {

// FIRST ANIMATION COMPLETE, CALL THE SECOND ANIMATION
startAnimation(mAlphaAnimation);
}
});

// SECOND ANIMATION
mAlphaAnimation = new AlphaAnimation(1.0f, 0.0f);
mAlphaAnimation.setDuration(PANEL_ALPHA_TRANSITION_TIME);
mAlphaAnimation.setFillAfter(true);

解决方法:

唯一能让我满意的方法是使用 AnimationSet,但将第二个动画的起始偏移设置为第一个动画的起始偏移 + 持续时间,再加上一点填充。在我的案例中,它们不必完全准确。

我尝试按照 CommonsWare 的建议使用各种值,但我总是会得到某种类型的“捕捉”效果,在这种情况下,这些值会在采用新值之前恢复到它们的原始值。

最佳答案

我发现我认为使用 AnimationSet.Builder 是 API 级别 11 及更高级别的理想解决方案类。

The Builder object is a utility class to facilitate adding animations to a AnimatorSet along with the relationships between the various animations. The intention of the Builder methods, along with the play() method of AnimatorSet is to make it possible to express the dependency relationships of animations in a natural way. Developers can also use the playTogether() and playSequentially() methods if these suit the need, but it might be easier in some situations to express the AnimatorSet of animations in pairs

For example, this sets up a AnimatorSet to play anim1 and anim2 at the same time, anim3 to play when anim2 finishes, and anim4 to play when anim3 finishes:

AnimatorSet s = new AnimatorSet();
s.play(anim1).with(anim2);
s.play(anim2).before(anim3);
s.play(anim4).after(anim3);

关于安卓链动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com