如何在android中旋转一个轮子(图像png)

Pra*_*sad 1 android android-emulator android-layout

我想在线性布局上旋转png图像.我的图像是半圆形的,上面有不同的颜色.

有任何想法吗?

use*_*305 6

使用Matrix你可以做到,

就像是,

img=(ImageView)findViewById(R.id.ImageView01);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.refresh);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

img.setImageDrawable(bmd);
Run Code Online (Sandbox Code Playgroud)

或使用动画

RotateAnimation rAnim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rAnim.setDuration(1000);
imageview.startAnimation(rAnim);
Run Code Online (Sandbox Code Playgroud)

编辑:看看这个问题如何在Android中进行平滑的图像旋转?

在Surface View中动画和旋转图像