我想让按钮在按下后立即永远旋转。 但这不起作用
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button2.setClickable(false);
while(true) {
button2.setRotation(button2.getRotation() + 1);
}
}
});
}`
最佳答案
当您按下按钮时,它将无限旋转。
rotate.xml(资源>动画>rotate.xml)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<rotate
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:fromDegrees="0"
android:toDegrees="360"
android:repeatCount="infinite"/>
</set>
您的按钮监听器
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
animation.setFillAfter(true);
btn.startAnimation(animation);
}
});
关于java - Android 中的无限按钮动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49011375/