在Android中将图像中心旋转轴移动到中心位置

7

我想要以中心为轴旋转一张图片。当我旋转图片时,我需要加载动态文本作为菜单,就像一个旋钮。请有人帮助我旋转一张图片。

1个回答

31

要旋转一张图片,您可以这样做:

RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

ImageView image = findViewById(my image);
image.setAnimation(rotate);

rotate.start();

这将使图像从0度旋转一圈到360度。您还可以设置旋转的持续时间:

rotate.setDuration( 500 ); // milliseconds

1
但是背景中的图像(包含ImageView的图像)没有旋转.. :) 并且需要帮助 :=) ? - cV2
1
你需要把图片设置为 ImageViewsrc,而不是 background - Nick
我已经将src设置好了,但是没有旋转,请帮忙一下好吗? - Saad Bilal
请使用 image.startAnimation(rotate) 代替 rotate.start()。 - Tushski

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接