我怎样才能提高转速

时间:2017-04-28 15:19:54

标签: java android animation

我想提高旋转速度。如何在此代码中增加ImageView的旋转速度?有人请帮助我。我需要帮助这个代码。提前谢谢。

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;
            }

        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

如果想要更快地旋转,则需要降低动画的持续时间。目前,您将其设置为持续50毫秒:

rotate.setDuration(50);

但您可以将持续时间设置为达到预期效果所需的任何时间。