본문 바로가기

공부/Android

안드로이드 Frame 애니메이션 구현

애니메이션 xml 코드 ( ex- bomb_ani.xml )

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="false">
    <item android:drawable="@drawable/bomb1" android:duration="50"/>
    <item android:drawable="@drawable/bomb2" android:duration="50"/>    
 </animation-list>

 
레이아웃 xml 내부에 들어갈 ImageView 코드

  <ImageView android:id="@+id/bombAni"
   android:layout_width="wrap_content"
android:layout_height="wrap_content"
   android:gravity="center"
   android:layout_centerHorizontal="true" 
   />


액티비티 java 코드에 들어갈 코드

onCreate()안에 들어갈 내용


ImageView bombAni = (ImageView)findViewById(R.id.bombAni);
bombAni.setBackgroundResource(R.anim.bomb_ani);
AnimationDrawable fanim =  (AnimationDrawable) bombAni.getBackground();

이렇게 지정 해준 다음에 외부에서 버튼 클릭시나 특정 이벤트 발생 시에
fanim.start(); 나 fanim.stop(); 으로 애니메이션 정지, 작동이 가능하다.





참고자료
http://developer.android.com/guide/topics/graphics/view-animation.html