我想在线性布局上旋转png图像。我的图像是半圆形的,上面有不同的颜色。
有什么想法吗?
答案 0 :(得分: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);
或使用动画
RotateAnimation rAnim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rAnim.setDuration(1000);
imageview.startAnimation(rAnim);
答案 1 :(得分:3)
可能对你旋转图像很有帮助.......
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
imageview.startAnimation(rotate);
开始和结束学位的前两个参数。
答案 2 :(得分:1)
这是我做过的帽子 计时器每隔100微秒调用一次tharaw方法 hw是图像的高度和宽度
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);
}