如何在android中旋转轮子(图像png)
我想在线性布局上旋转png图像。我的图像是半圆形状,上面有不同的颜色如何在android中旋转轮子(图像png),android,android-layout,android-emulator,Android,Android Layout,Android Emulator,我想在线性布局上旋转png图像。我的图像是半圆形状,上面有不同的颜色 有什么想法吗?可能有助于你旋转图像 RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(500); imageview.startAnimation(rotate); 度的开始和结束的前
有什么想法吗?可能有助于你旋转图像
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
imageview.startAnimation(rotate);
度的开始和结束的前两个参数。可能有助于u旋转图像
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
imageview.startAnimation(rotate);
度的开始和结束的前两个参数。使用矩阵可以执行此操作 大概
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);
编辑:也看看这个问题
使用矩阵你可以做到 大概
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);
编辑:也看看这个问题
这是我做的帽子
计时器每100微秒调用一次pondraw mthod
h、 w是图像的高度和宽度
new CountDownTimer(2000, 100) {
public void onTick(long millisUntilFinished) {
degrees=degrees +(rm.nextFloat()*100);
postInvalidate();
}
public void onFinish() {
}
}.start();
将此代码放入ondraw方法中
Matrix m = new Matrix();
m.setRotate(degrees,w/2,h/2);
bmp=BitmapFactory.decodeResource(context.getResources(),R.drawable.wfortune_wheel);
canvas.drawBitmap(bmp, m, pb);
}这是我做的帽子
计时器每100微秒调用一次pondraw mthod
h、 w是图像的高度和宽度
new CountDownTimer(2000, 100) {
public void onTick(long millisUntilFinished) {
degrees=degrees +(rm.nextFloat()*100);
postInvalidate();
}
public void onFinish() {
}
}.start();
将此代码放入ondraw方法中
Matrix m = new Matrix();
m.setRotate(degrees,w/2,h/2);
bmp=BitmapFactory.decodeResource(context.getResources(),R.drawable.wfortune_wheel);
canvas.drawBitmap(bmp, m, pb);
}+1用于参考:“如何在Android中进行平滑图像旋转?”+1用于参考:“如何在Android中进行平滑图像旋转?”