效果:点击按钮后按照设定的角度旋转按钮。
具体实现步骤:
1、添加rotate(旋转)配置文件:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"<!-- 设置旋转持续时间 -->
android:fromDegrees="0"
android:interpolator="@android:anim/accelerate_interpolator"<!-- 设置旋转速度 -->
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="90" ><!-- 设置旋转角度 -->
</rotate>
2、在Activity中使用Animation
add_notes_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(BookNotesListActivity.this, R.anim.rotate);
add_notes_btn.setAnimation(animation);
Intent intent = new Intent();
intent.setClass(getApplicationContext(), AddNoteActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "添加笔记", Toast.LENGTH_SHORT).show();
}
});