gpt4 book ai didi

android - TranslateAnimation 完成后跳回起点

转载 作者:行者123 更新时间:2023-11-29 14:18:32 27 4
gpt4 key购买 nike

我的 TranslateAnimation 有效,但在动画结束时,它会跳回原来的位置。

        LinearLayout rl = (LinearLayout) findViewById(R.id.navPanel);

animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 3.0f
);
animation.setDuration(500);

rl.startAnimation(animation);

如何让它留在结束位置?

最佳答案

旧的(3.0 之前的)Animation API 表现得有点奇怪 - 当它设置动画时,它只是转换绘制 View 的位置,但实际上并没有相对于其父 View 移动 View 。

为了让 View 在动画完成后保持不变,您可以在 TranslateAnimation 上设置一个 Animation.AnimationListener。在监听器的 onAnimationEnd() 方法中,您可以通过操作 View 上的 LayoutParams 将 View 移动到它的最终位置。

关于android - TranslateAnimation 完成后跳回起点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7919259/

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