我有一个需要淡入的按钮。但它只在第一次起作用。第二次就不行了。
这是我的代码。
final TextView doctorInfoView = (TextView) rowView.findViewById(R.id.doctorInfo);
final TextView specialtyView = (TextView) rowView.findViewById(R.id.specialty);
final ImageButton deleteDoctor = (ImageButton)rowView.findViewById(R.id.deleteDoctor);
final Animation fadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_in_animate);
final ImageButton editDoctor = (ImageButton)rowView.findViewById(R.id.editDoctor);
final RelativeLayout mainRowLayout = (RelativeLayout)rowView.findViewById(R.id.doctorListInfoView);
final LinearLayout rowLayout = (LinearLayout)rowView.findViewById(R.id.doctorInfoLayout);
final LinearLayout editButtonLayout = (LinearLayout)rowView.findViewById(R.id.editButtonLayout);
final LinearLayout deleteButtonLayout = (LinearLayout)rowView.findViewById(R.id.deleteButtonLayout);
rowLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isClicked) {
editDoctor.setAnimation(fadeInAnimation);
editDoctor.setVisibility(View.VISIBLE);
deleteDoctor.setAnimation(fadeInAnimation);
deleteDoctor.setVisibility(View.VISIBLE);
mainRowLayout.setBackgroundColor(Color.parseColor("#ffffff"));
doctorInfoView.setTextColor(Color.parseColor("#eeeeee"));
specialtyView.setTextColor(Color.parseColor("#eeeeee"));
editButtonLayout.setBackgroundColor(Color.parseColor("#16aea3"));
deleteButtonLayout.setBackgroundColor(Color.parseColor("#16aea3"));
isClicked = false;
} else {
editDoctor.setVisibility(View.GONE);
deleteDoctor.setVisibility(View.GONE);
mainRowLayout.setBackgroundColor(Color.parseColor("#f2f2f4"));
doctorInfoView.setTextColor(Color.parseColor("#000000"));
specialtyView.setTextColor(Color.parseColor("#0d9e9f"));
editButtonLayout.setBackgroundColor(Color.parseColor("#f2f2f4"));
deleteButtonLayout.setBackgroundColor(Color.parseColor("#f2f2f4"));
isClicked = true;
}
}
});
这里是fade_in_animate.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"/>
</set>
如果有任何反馈,我将不胜感激。
最佳答案
解决这个问题的一种方法是将动画设置为空
editDoctor.setVisibility(View.GONE);
editDoctor.setAnimation(null);
编辑:你忘了将它设置为无限
animation.setRepeatCount(Animation.INFINITE);
这是xml
android:repeatCount="-1"
android:repeatMode="repeat"
这是完整的 documentation
编辑 2:我没有看到您正在设置 alpha。我的错。这应该工作!你不需要重复它。这将与将动画设置为 null
的方法一起使用。
editDoctor.setVisibility(View.GONE);
editDoctor.setAnimation(null);
editDoctor.setAlpha(.0f);
关于android - 动画第二次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36722640/