i want to increase the rotation speed.How can I increase the rotation speed of the ImageView in this code ??anyone please help me.I need help with this code. Thanks in advance.
public class MainActivity extends Activity {
ImageView img_one;
Button btn_one;
Random r;
int angle;
boolean restart=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img_one = (ImageView) findViewById(R.id.imageView_ring);
r=new Random();
btn_one = (Button) findViewById(R.id.btn_1);
btn_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (restart){
angle=angle & 360;
angle=r.nextInt()+360;
RotateAnimation rotate=new RotateAnimation(angle,360,RotateAnimation.RELATIVE_TO_SELF,0.5f,
RotateAnimation.RELATIVE_TO_SELF,0.5f);
rotate.setFillAfter(true);
rotate.setDuration(50);
rotate.setInterpolator(new AccelerateDecelerateInterpolator());
img_one.startAnimation(rotate);
restart=false;
}else {
angle=r.nextInt()+360;
RotateAnimation rotate=new RotateAnimation(0,angle,RotateAnimation.RELATIVE_TO_SELF,0.5f,
RotateAnimation.RELATIVE_TO_SELF,0.5f);
rotate.setFillAfter(true);
rotate.setDuration(50);
rotate.setInterpolator(new AccelerateDecelerateInterpolator());
img_one.startAnimation(rotate);
restart=true;
}
}
});
}
}
If you want to rotate faster, you need to lower the duration of the animation. Currently you have it set to last for 50 milliseconds:
rotate.setDuration(50);
but you can set the duration to whatever you need to achieve your desired effect.