android - 动画第二次不起作用

标签 android

我有一个需要淡入的按钮。但它只在第一次起作用。第二次就不行了。

这是我的代码。

    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/

相关文章:

android - 如何在Android应用程序中访问网络摄像头的实时流

android - RecyclerView 回到位置 0

android - Android Studio app.gradle错误:程序类型已存在:android.support.v4.app.BackStackRecord $ Op

android - react native : Could not find support-vector-drawable. aar

java - 从位图android的边缘创建路径

Android:获取当前位置后禁用 onLocationChanged()

c# - Android 锁屏 C# .NET 副本

android - 没有找到 void org.tensorflow.demo.env.ImageUtils 的实现

android - 如何获取列表中应用程序的图标?

android:如何在折叠工具栏中添加带有文本的按钮