我如何获得一个ImageView的,而在Android的翻译旋转? [英] How do I get an imageview to rotate while translating in Android?
问题描述
我试图让,虽然在屏幕上滑动旋转的ImageView的。我安装一个旋转的动画为180度,它的工作方式本身。我安装一个转换动画和它的作品本身。当我将它们结合起来,我得到一个ImageView的,使一个大循环。我想的ImageView来绕的ImageView的中心,而被翻译。
AnimationSet动画集=新AnimationSet(真正的);
//翻译向上和向右。
TranslateAnimation动画=
新TranslateAnimation(
Animation.ABSOLUTE,0.0,Animation.ABSOLUTE,+ 80.0f,
Animation.ABSOLUTE,0.0,Animation.ABSOLUTE,-100.0f
);
anim.setInterpolator(新DecelerateInterpolator());
anim.setDuration(400);
animSet.addAnimation(动画);
周围ImageView的中心//旋转
RotateAnimation ranim =新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(新DecelerateInterpolator());
animSet.addAnimation(ranim);
imageBottom.startAnimation(动画集);
嗯,我想我橡胶躲开这之一。
订单的动画应用问题。我换了顺序平移/旋转旋转/平移和它的作品。
I am trying to make an imageview that rotates while sliding across the screen. I setup a rotate animation for 180 degrees, and it works by itself. I setup a translate animation and it works by itself. When I combine them I get an imageview that makes a big spiral. I would like the imageview to rotate around the center of the imageview while being translated.
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);
Well I guess I "rubber ducked" this one.
The order that the animations are applied matters. I switched the order from translate/rotate to rotate/translate and it works.
这篇关于我如何获得一个ImageView的,而在Android的翻译旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!