[英]android what should be pivot point to rotate image around its center of base
在标记重复或关闭之前,请仔细阅读整个问题
我想围绕其基点的中心点旋转图像(特别是箭头图像 )。
例如,在开始时,我的图像将像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度。
我希望将来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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.