android中心点旋转晃动_android应该是枢轴点以围绕其中心旋转图像

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.

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.

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);

or second code

Matrix matrix = new Matrix();

imageView.setScaleType(ScaleType.MATRIX);

matrix.postRotate((float) 20, 0f, 0f);

imageView.setImageMatrix(matrix);

or third code

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);

or fourth code

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);

Added an image for better understanding which rotated in 90 degrees along clockwise.

And I hope in future google will add more and clear documentation about the pivot points.

Thanks in advance.

解决方案

You were almost right with the fourth code ^^

You can achieve this like that :

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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值