Dennis avatar

[Android Studio] FrameAnimation 적용해보기

ractea

Published: 21 Jul 2018 › Updated: 21 Jul 2018[Android Studio] FrameAnimation 적용해보기

[Android Studio] FrameAnimation 적용해보기

Android Studio 입문강의를 듣고 있다. Android Studio는 Java언어를 사용하기 때문에 먼저  Java를 숙지하는 것이 좋다.  초보자의 입장에서 Java의 대표적 컴파일러인 Eclipse보다 Android Studio가 자동완성기능도 잘 구현되어 있고 직관적으로 구동현황을 보면서 코딩할 수 있어서 사용하기 편했다.

Android Studio Animation 기능 중에서 이미지로 애니메이션 효과를 낼 수 있는FrameAnimation에 대해서 살펴보자!

 1. 우선  FrameAnimation을 구현할 이미지를 구한다.

res - drawable 폴더에 이미지를 넣어준다.

activity_main.xml 파일에서 LinearLayout을 이용해 레이아웃을 잡아준다.

activity_main.xml 의 예시 코드를 적어보면

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/truck"
    android:background="@drawable/intro_background1"/>
  </LinearLayt> 

 2. drawable 폴더에 FrameAnimation을 구현할 이미지의 코드를 작성할 xml 파일을 만든다.

ex) intro_background.xml

[ Example ] 

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/intro_background1" android:duration="300" />
    <item android:drawable="@drawable/intro_background2" android:duration="300" />
    <item android:drawable="@drawable/intro_background3" android:duration="300" />
    <item android:drawable="@drawable/intro_background4" android:duration="300" />
    <item android:drawable="@drawable/intro_background5" android:duration="300" />
    <item android:drawable="@drawable/intro_background6" android:duration="300" />
</animation-list> 

 3. 마지막으로 MainActivity.java 파일의 코드를 구현한다.

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView img = findViewById(R.id.truck);
        final AnimationDrawable ani = (AnimationDrawable) img.getBackground();
        {   
        ani.start();
        }
    }
}

Leave [Android Studio] FrameAnimation 적용해보기 to:

Written by

Read more #androidstudio posts


Best Posts From Dennis

We have not curated any of ractea's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Dennis