2014-12-09 4 views
-1

나는이 애니메이션을 단일 이미지로 만들고 싶다. 움직이거나 알파처럼 다른보기 애니메이션을 적용하고 싶었다. 어떻게 할 수 있는가? 어떤 생각? 단순히 드로잉 가능한 애니메이션에 뷰 애니메이션을 적용하고 싶었습니다.안드로이드에서 애니메이션을 움직이게하는 방법

내가 XML은

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false"> 
<item android:drawable="@drawable/s1" android:duration="200" /> 
<item android:drawable="@drawable/s2" android:duration="200" /> 
<item android:drawable="@drawable/s3" android:duration="200" /> 
<item android:drawable="@drawable/s12" android:duration="200" /> 
<item android:drawable="@drawable/s13" android:duration="200" /> 
<item android:drawable="@drawable/s14" android:duration="200" /> 
<item android:drawable="@drawable/s15" android:duration="200" /> 
<item android:drawable="@drawable/s16" android:duration="200" /> 

</animation-list> 

이다 S16 할 S1, S2, S3, S4와 같은 일부 그릴 수 있고 자바 코드가 여기

anim = (ImageView) findViewById(R.id.black); 
    anim.setBackgroundResource(R.drawable.smurf); 
    AnimationDrawable hello = (AnimationDrawable) anim.getBackground(); 
    hello.start(); 

입니다 당김에 스머프 당김 애니메이션에 대한 XML 파일입니다 .

+0

하시기 바랍니다 어떤 대답이나 코멘트 –

+0

이 페이지를보십시오 http://developer.android.com/guide/topics/resources/animation-resource.html –

+0

고마워요.하지만 프레임 애니메이션을 캡슐화하고 싶습니다. on Tween 애니메이션. –

답변

0

우리는 그 애니메이션을 할 수 있지만 그 핸들러를 유지해야합니다. 당신의 onclick에

private int index = 0; 
    private Handler handler = new Handler(); 
    private AnimationDrawable drawable; 

Runnable runnable = new Runnable() { 

    @Override 
    public void run() { 
     imageView.setImageDrawable(drawable.getFrame(index)); 
     index++; 
     if (index == drawable.getNumberOfFrames()) { 
      index = 0; 
     } 
     handler.postDelayed(runnable, drawable.getDuration(index)); 
    } 
}; 

또는이 같은 애니메이션 쓰기 시작할 위치 :

handler.postDelayed(runnable, drawable.getDuration(index)); 

하고 onDestroy()이 같은 handeler 통화 백업을 제거하십시오 :

protected void onDestroy() { 
     super.onDestroy(); 
     handler.removeCallbacks(runnable); 
    } 
+0

내 대답은 당신에게 유용한가? –

관련 문제