2012-10-16 5 views
1

나는 다운로드 버튼이있는 목록보기를 사용하고 있습니다.ListView 문제의 버튼 애니메이션

나는 어떤 배경 다운로드 프로세스가 작동 할 때까지 클릭 이벤트를 발생시키고 버튼을 회전시키고 싶다.

회전은 정상적으로 작동하지만 한 사이클이 완료되면 약간 지연됩니다.

주요 문제는 버튼이 애니메이션 처리되고 사용자가 스크롤 목록 다른 행의 다른 버튼도 애니메이션을 시작한다는 점입니다.

나는 부울 유형 배열 버튼 상태를 유지할 isDownloading []입니다. 그래서 내가 그 위치에 버튼을 얻을 애니메이션을 시작하지만 애니메이션 이리저리 버튼을 얻기 위해 문제를

코드를 생성 :

public void ButtonAnimate(Button b) 
     { 
      RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
      animation.setDuration(4500); 
      animation.setRepeatCount(100); 
      b.startAnimation(animation); 
     } 

답변

3

모든 : 버튼을 애니메이션하기

else if (isDownloading[position] == true) 
     { 
            holder.downloadListBtn.setBackgroundResource(R.drawable.downloading); 
            LinearLayout layout = (LinearLayout) holder.downloadListBtn.getParent(); 
            Button button = (Button) layout.getChildAt(0); 
            ButtonAnimate(button); 
     } 

코드 버튼에 동일한 ID가 있기 때문에 애니메이션이 시작됩니다. 초점이 잡히면 애니메이션이 시작됩니다. 그래서, 당신이해야 할 일은 다른 ID 나 태그를 할당하는 것입니다.

해당 ID와 태그를 기준으로 해당 버튼을 회전 시키십시오.

버튼에이 코드가

여기
Rotater.runRotatorAnimation(this, v.getId()); 

public class Rotater { 
public static void runRotatorAnimation(Activity act, int viewId) { 

    // load animation XML resource under res/anim 
    Animation animation = AnimationUtils.loadAnimation(act, R.anim.rotate); 
    if (animation == null) { 
     return; // here, we don't care 
    } 
    // reset initialization state 
    animation.reset(); 
    // find View by its id attribute in the XML 
    View v = act.findViewById(viewId); 
    // cancel any pending animation and start this one 
    if (v != null) { 
     v.clearAnimation(); 
     v.startAnimation(animation); 
    } 
} 
} 

이 rotate.xml입니다 클릭하십시오

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator" > 
    <rotate 
    android:duration="2000" 
    android:fromDegrees="0" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="infinite" 
    android:startOffset="0" 
    android:toDegrees="360" > 
    </rotate>