为什么我的onclick不能触发Animation Imageview

Why my onclick can't trigger Animation Imageview

我想使用 Onclick() 使我的图像视图旋转到随机角度。但为什么 Onlick() 有效但 Imageview 不能旋转?这是我的代码。

ImageView rotate_plate;
Button debug_button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    debug_button=(Button) findViewById(R.id.test_button);
    debug_button.setOnClickListener(btngoOnClick);

}
private OnClickListener btngoOnClick = new OnClickListener() {
    public void onClick(View v) {

        debug_button.setText("Click");
        rotate_plate=(ImageView) findViewById(R.id.wheel);
        int stopturnnum = (int)(Math.random() *360);
        Animation am = new RotateAnimation(0, stopturnnum, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

        am.setDuration( 3000 );
        am.setRepeatCount(1);
        am.setFillAfter(true);
        rotate_plate.setAnimation(am);
        am.startNow();
    }
};

试试 ViewPropertyAnimator API,这样更方便:

rotate_plate.animate()
    .rotation(angle)
    .setDuration(3000L)