본문 바로가기
안드로이드 자바

[Android][Java] 로고 애니메이션 넣어주기

by teamnova 2024. 2. 2.
728x90

안녕하세요. 오늘은 스플래시 화면 즉, 초기 로딩화면에서 로고가 애니메이션이 적용되어 보여지게 작업할 예정입니다.

우선 xml파일부터 작성해보겠습니다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center">
    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/heptagon_background"
        android:id="@+id/logo"/>
</LinearLayout>

다음에는 res폴더에 anim 폴더를 생성하고 그 안에 logo_animation.xml파일을 생성해주세요.

파일 코드는 아래와 같습니다.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="0.5"
        android:fromYScale="0.5"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000" />
</set>

다음은 자바 파일입니다.


public class MainActivity extends AppCompatActivity {
    Context context;
    ImageView logo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        logo = findViewById(R.id.logo);

        Animation logoAnimation = AnimationUtils.loadAnimation(context,R.anim.logo_animation);

        logo.startAnimation(logoAnimation);
        
    }


}

 

위 실행 영상은 아래에 있습니다.