【发布时间】:2015-03-26 13:21:34
【问题描述】:
请在标记重复或关闭之前仔细阅读整个问题
我想围绕其中心点旋转图像(特别是箭头图像)。
例如一开始,我的形象就像 9 点钟的秒针。 假设我将该图像旋转 30 度,它应该看起来像 10 上的时钟秒针,如果 120 度,它应该看起来像 1 上的时钟秒针。
所以我想围绕它的中心(沿 x 轴)旋转该图像。
如果我第一次编码,我应该将什么作为枢轴(X & Y) 传递
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 度,添加了一张图片。
我希望未来谷歌会添加更多关于枢轴点的清晰文档。
提前致谢。
【问题讨论】:
标签: android image rotation image-rotation rotateanimation