Android 安卓-动画不';我第二次不工作了

Android 安卓-动画不';我第二次不工作了,android,Android,我有一个按钮需要淡入。但它只在第一次起作用。第二次就不行了 这是我的密码 final TextView doctorInfoView = (TextView) rowView.findViewById(R.id.doctorInfo); final TextView specialtyView = (TextView) rowView.findViewById(R.id.specialty); final ImageButton deleteDoctor = (Imag

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

这是我的密码

    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"
这是全文


编辑2:我没有看到您正在设置alpha。我的错。这应该管用!你不需要重复。这将与将动画设置为
null
的方法一起使用

editDoctor.setVisibility(View.GONE);
editDoctor.setAnimation(null);
editDoctor.setAlpha(.0f);

不,不行。它的行为相同。它只在第一次起作用。当我多次单击时,它不起作用。它不应该重复。所以我修改了你的代码如下,android:repeatCount=“0”。这是一个按钮。我不想让它眨眼。我只希望它在用户单击背景布局时淡入,在用户再次单击时消失。当我第一次单击背景布局时,按钮会淡入淡出,但第二次它会弹出,而不是淡入淡出。你的代码仍然不起作用。无论如何,谢谢你。