I want to rotate a png image on linear layout. My image is semi circle in shape and have different colors on it.
Any ideas?
I want to rotate a png image on linear layout. My image is semi circle in shape and have different colors on it.
Any ideas?
Using Matrix you can do it,
Something like,
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);
OR Use Animation
RotateAnimation rAnim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rAnim.setDuration(1000);
imageview.startAnimation(rAnim);
EDIT: Look at this question also How to make a smooth image rotation in Android?
might be helpful for u to rotating image.......
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
imageview.startAnimation(rotate);
first two parameter for start and end of degree.
This is hat i have done the timer calls the pondraw mthod after every 100micro seconds h,w are height and width of the image
new CountDownTimer(2000, 100) {
public void onTick(long millisUntilFinished) {
degrees=degrees +(rm.nextFloat()*100);
postInvalidate();
}
public void onFinish() {
}
}.start();
put this code in ondraw method
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);
}