I am developing an android app where I have to rotate a circular image around another circular image, but when I am running this the size of my circular image gets automatically changing continuously. So please help me how to solve this. Here is my code
public class JobSearch extends Activity implements OnTouchListener {
private ImageView dialer;
private float y=0;
public boolean onTouch(View v, MotionEvent event) {
double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2-event.getY());
int rotation=(int)Math.toDegrees(r);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
//x=event.getX();
y=event.getY();
updateRotation(rotation);
break;
case MotionEvent.ACTION_UP:
break;
}//switch
return true;
}//onTouch
private void updateRotation(double rot){
float newRot=new Float(rot);
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.round_button_big);
Matrix matrix=new Matrix();
matrix.postRotate(newRot);//,bitmap.getWidth()/2,bitmap.getHeight()/2);
Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
dialer.setImageBitmap(reDrawnBitmap);
if(newRot>=-5 && newRot<=5)
Toast.makeText(this,"12 O\'Clock",Toast.LENGTH_SHORT).show();
if(newRot>=85 && newRot<=95)
Toast.makeText(this,"3 O\'Clock",Toast.LENGTH_SHORT).show();
if(newRot>=175 || newRot<=-175)
Toast.makeText(this,"6 O\'Clock",Toast.LENGTH_SHORT).show();
if(newRot>=-95 && newRot<=-85)
Toast.makeText(this,"9 O\'Clock",Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dialer = (ImageView) findViewById(R.id.big_button);
dialer.setOnTouchListener(this);
}//onCreate
}
This is my code to rotate image around itself and slowly reduce the speed
This this one; worked for me perfectly.
this is the code of rotate the image
Try this code for Rotating Image -
And, also see this Tutorial