如android文档所述,
setAnimationListener
侦听器通知动画的重复。
,这意味着每次重复动画(在我的情况下为5次),它都应在onAnimationRepeat
函数下执行语句。但是onAnimationRepeat
即使我的动画重复了5次,也不会收听。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:shareInterpolator="false">
<rotate
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="3000"
android:repeatCount="5"
/>
</set>
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
imgLogo.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
sharedPreferences = MainActivity.this.getSharedPreferences("Login", MODE_PRIVATE);
Log.d(TAG, "sharedpreferences: "+sharedPreferences.getString("Unm",null));
if(sharedPreferences.contains("Unm")){
FirebaseDatabase.getInstance()
.getReference("users")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.d(TAG, "sharedpreferences: "+sharedPreferences.getString("Unm",null));
User.currentUser = dataSnapshot.child(sharedPreferences.getString("Unm",null))
.getValue(userModel.class);
imgLogo.clearAnimation();
Intent intent = new Intent(MainActivity.this, food_menu.class);
startActivity(intent);
finish();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
Log.d(TAG, "onAnimationRepeat: ");
if(sharedPreferences.contains("Unm")){
return;
} else{
animation.cancel();
imgLogo.clearAnimation();
btnset.setVisibility(View.VISIBLE);
}
}
});