Shi*_*ade 5 android image rotation image-rotation rotateanimation
在标记重复或关闭之前,请仔细阅读整个问题
我想围绕其基点的中心点旋转图像(特别是箭头图像).
例如,在开始时,我的图像将像9中的时钟中的秒针.并且假设如果我将该图像旋转30度,它应该看起来像时钟秒针10和120度时钟秒针1.
所以我想围绕它的基座中心(沿x轴)旋转那个图像.
那么如果我第一次编码,我应该作为枢轴(X和Y)传递什么
imageView.setPivotX(1f);
imageView.setPivotY(1f);
imageView.setRotation(-30);
Run Code Online (Sandbox Code Playgroud)
或第二个代码
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
matrix.postRotate((float) 20, 0f, 0f);
imageView.setImageMatrix(matrix);
Run Code Online (Sandbox Code Playgroud)
或第三代码
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);
Run Code Online (Sandbox Code Playgroud)
或第四个代码
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);
Run Code Online (Sandbox Code Playgroud)
添加了一个图像,以便更好地理解沿顺时针方向旋转90度.
我希望将来google会添加更多关于支点的文档.
提前致谢.
第四个代码^^几乎是对的
你可以这样做:
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();
Run Code Online (Sandbox Code Playgroud)