0

recently I wrote a function.it's about a refresh button in each list item. what I want is click the button or List Item, the refresh button starts rotate. stops when the request finished. I use animation as follows:

<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fillAfter="true"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:toDegrees="358" />

and some source code are here:

public void refresh(View v) {

    Animation rotation = AnimationUtils.loadAnimation(mContext,
            R.anim.rotate);
    rotation.setFillAfter(true);
    v.startAnimation(rotation);

}

public void completeRefresh(View v) {
    v.clearAnimation();
}

when the request finished, I call notifyDataSetChanged() to refresh the LiseView.

the problem is that the button was indeed rotating. but when I click it the second time. it's rotating but a little fuzzy. just like this:

enter image description here

any suggestions? thanks a lot.

Jaden Gu
  • 9,143
  • 3
  • 23
  • 26

1 Answers1

0

What is most likely happening on your second (and subsequent clicks) is that the animation is running on it again.

In your current implementation, try using setTag(...) like this:

public void refresh(View v) {
    if(v.getTag() != null && (boolean)v.getTag()) {
        //do nothing, since we are setting the tag to be true once pressed
    } else {
        //this view hasn't been clicked yet, show animation and set tag
        v.setTag(true);
        Animation rotation = AnimationUtils.loadAnimation(mContext, R.anim.rotate);
        rotation.setFillAfter(true);
        v.startAnimation(rotation);
    }
}

In your Adapter, you should keep track of which list items are being animated (I'm assuming multiple items can be clicked at the same time). Once you know that the 'request' is finished, you can update the adapter with the correct items and then call notifyDataSetChanged()

Hahn
  • 424
  • 3
  • 11
  • Thanks. finally I found that when I remove the google ad banner. it works like a charm. I haven't had time to know exactly the reason. Let's go and see. – Jaden Gu Nov 14 '14 at 06:00