废话不多,上代码:
final Animation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
final ImageButton buttonDraw = (ImageButton) findViewById(R.id.drawer_button);
buttonDraw.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
rotateAnimation.setDuration(300);
buttonDraw.startAnimation(rotateAnimation);
}
});
第一行前两个参数是旋转的起始与终止位置,后面四个看提示的pivot,就知道是个轴,0.5代表组件的中间。