代码:
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final RotateAnimation animation = new RotateAnimation(0.0f, 180.0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration( 500 );
btn.startAnimation( animation );
}
});
布局:
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"/>
本文介绍了一种使用Java代码在Android应用中实现按钮180度旋转动画的方法。通过设置监听器,当按钮被点击时,将触发旋转动画,动画时间为500毫秒,旋转中心位于按钮的中心。
221

被折叠的 条评论
为什么被折叠?



