2011-08-08 4 views
3

터치 이벤트의 도움으로 Android의 활동에서 이미지 휠을 돌릴 수 있습니까? 튜토리얼의 가이드 라인이나 링크가 필요합니다.Android의 회전 휠

+0

당신이 제시해야 할 그것은 애니메이션이나 진행을 위해? – Hanry

+0

check http://stackoverflow.com/questions/2140023/android-hourglass – Fortega

답변

3

이것은 일반적으로 몇 조각으로 이루어집니다. 이것은 내가 나의 애플 리케이션 중 하나에서 그것을하는 방법이다. * 참고 :이 휠은 매끄러운 휠이 아니므로 맨 위 (의도적으로)에서 시작하고 멈 춥니 다. dev site에서 Animation에 대한 자세한 내용을 조회 할 수 있습니다.

이미지가

홈페이지 XML : 여기

<ImageView 
    android:id="@+id/anim_example" 
    android:src="@drawable/loading_circle" 
    android:layout_width="30sp" 
    android:layout_height="30sp" 
    android:onClick="RunAnimation" /> 

애니메이션을 실행하는 코드의 부분입니다을

public void RunAnimation(View v) 
{ 
    //The onClick method has to be present and must take the above parameter. 
    StartLoading(); 

    //This will delay the stop for 5 seconds 
    //Normally you would want to actually have this run based on some other input/data. 
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     public void run() { 
      StopLoading(); 
     } 
    }, 5000); 
} 

public void StartLoading() { 
    ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example); 
    refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle)); 
    Animation rotateLoading = AnimationUtils.loadAnimation(this, R.anim.rotate); 
    refreshImage.clearAnimation(); 
    refreshImage.setAnimation(rotateLoading); 
} 

public void StopLoading() { 
    ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example); 
    if (refreshImage.getAnimation() != null) 
    { 
     refreshImage.clearAnimation(); 
     refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle)); 
    } 
} 

anim.rotate :

<?xml version="1.0" encoding="utf-8"?> 
<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="359" 
    android:duration="2000" 
    android:repeatMode="restart" 
    android:repeatCount="-1" 
    android:pivotX="50%" 
    android:pivotY="50%"> 
</rotate>