티스토리 뷰

2가지 방법, 

 

 

1. xml 사용 한 구현 방법

 

1). xml 생성

res\drawable\ 안에 xml 생성

 

<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">

<item android:drawable="@drawable/animation_1" android:duration="50"/>
<item android:drawable="@drawable/animation_2" android:duration="50"/>
<item android:drawable="@drawable/animation_3" android:duration="50"/>

</animation-list>

 

2). imageView에 위에서 생성한 animation src로 적용

 

<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animation_list"/>

 

3). activity java 로 구현

ImageView animation = findViewById(R.id.imsi_animation);
AnimationDrawable animationDrawable = (AnimationDrawable) imsi_animation.getDrawable();
animationDrawable.start();

 

-------------------------------------------------------------------------------------------------------------------

 

2. all java로 구현

 

ImageView animation = findViewById(R.id.imsi_animation);

AnimationDrawable animationDrawable = new AnimationDrawable();
animationDrawable.addFrame(getResources().getDrawable(R.drawable.animation_1),25);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.animation_2),25);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.animation_3),25);

animation.setImageDrawable(animationDrawable);

 

// 25는 duration

// animationDrawable.setOneShot(false); 코드 추가하면 애니메이션 반복 됨, 

 

 

 

 

'android' 카테고리의 다른 글

retrofit  (0) 2022.09.21
by viewmodels() 쓰는법,  (0) 2022.08.18
AnimationDrawable memory 문제.  (0) 2020.04.27
안드로이드 SurfaceView Video 예제  (0) 2020.01.31
ExoPlayer 사용 법.  (0) 2020.01.31