如何旋转机器人的轮子(图像PNG) [英] How to rotate a wheel (image png) in android

查看:128
本文介绍了如何旋转机器人的轮子(图像PNG)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要旋转一个PNG图像线性布局。我的形象的形状半圈,有不同的颜色就可以了。

I want to rotate a png image on linear layout. My image is semi circle in shape and have different colors on it.

任何想法?

推荐答案

使用矩阵,你可以做到这一点,

Using Matrix you can do it,

喜欢的东西,

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

或使用动画

RotateAnimation rAnim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rAnim.setDuration(1000);
imageview.startAnimation(rAnim);

编辑:看看这个问题也的如何使一个平滑的图像旋转的Andr​​oid?

Look at this question also How to make a smooth image rotation in Android?

<一个href="http://stackoverflow.com/questions/2439301/animating-and-rotating-an-image-in-a-surface-view">Animating并在表面观旋转图像

这篇关于如何旋转机器人的轮子(图像PNG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆