gpt4 book ai didi

java - 在 Android 中翻译时如何让 ImageView 旋转?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:31 25 4
gpt4 key购买 nike

我正在尝试制作一个在屏幕上滑动时旋转的 ImageView 。我设置了一个 180 度的旋转动画,它会自动运行。我设置了一个翻译动画,它自己工作。当我将它们组合在一起时,我得到一个形成大螺旋的 ImageView 。我希望 ImageView 在翻译时围绕 ImageView 的中心旋转。

        AnimationSet animSet = new AnimationSet(true);
//Translate upwards and to the right.
TranslateAnimation anim =
new TranslateAnimation(
Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, +80.0f,
Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -100.0f
);
anim.setInterpolator(new DecelerateInterpolator());
anim.setDuration(400);
animSet.addAnimation(anim);

//Rotate around center of Imageview
RotateAnimation ranim = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //, 200, 200); // canvas.getWidth() / 2, canvas.getHeight() / 2);
ranim.setDuration(400);
ranim.setInterpolator(new DecelerateInterpolator());

animSet.addAnimation(ranim);

imageBottom.startAnimation(animSet);

最佳答案

嗯,我想我 "rubber ducked"这个。

动画的应用顺序很重要。我将顺序从翻译/旋转切换为旋转/翻译并且它有效。

关于java - 在 Android 中翻译时如何让 ImageView 旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2520672/

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