android应该是枢轴点以围绕其中心旋转图像 [英] android what should be pivot point to rotate image around its center of base
问题描述
在标记重复或关闭它之前,请仔细阅读整个问题
Please read the whole question carefully before marking duplicate or closing it
我要旋转图像(特别是箭头图像)在其中心点附近。
I want to rotate a image(specifically arrow image) around its center point of base.
例如开始时,我的图像就像是9时针上的秒针。
并且假设如果我将图像旋转30度,它应该看起来像是10时针的秒针,如果是120时则是1针的秒针。
e.g. At start my image will be like second hand in a clock on 9. And suppose if I rotate that image by 30 degree, it should look like clock second hand on 10 and if 120 degree the clock second hand on 1.
所以我想围绕该图像的中心(沿x轴)旋转图像。
So I want to rotate that image around it's center(along x axis) of base.
那又怎样?如果我先编写代码
So what should I pass as pivot(X & Y) if I first code
imageView.setPivotX(1f);
imageView.setPivotY(1f);
imageView.setRotation(-30);
或第二个代码
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
matrix.postRotate((float) 20, 0f, 0f);
imageView.setImageMatrix(matrix);
或第三个代码
Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_0_degree);
Matrix matrix = new Matrix();
matrix.postRotate(30);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 1, myImg.getWidth(), myImg.getHeight(), matrix, true);
imageView.setImageBitmap(rotated);
或第四个代码
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
添加了一个图像以便更好地理解,该图像沿顺时针方向旋转了90度。
Added an image for better understanding which rotated in 90 degrees along clockwise.
我希望以后的Google会添加更多和清晰的有关枢轴点的文档。
And I hope in future google will add more and clear documentation about the pivot points.
预先感谢。
推荐答案
使用第四个代码^^
您可以实现以下目标:
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, 30,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 1f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
mImageView.setAnimation(rotateAnim);
rotateAnim.start();
这篇关于android应该是枢轴点以围绕其中心旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!