본문 바로가기

공부/안드로이드

화면 가운데로 축소되어 사라지는 애니메이션

그냥 애니메이션 XML에 scale 만 넣어주면 될줄 알았는데


<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale

        android:fromXScale="1"

        android:fromYScale="1"

        android:toXScale="0"

        android:toYScale="0"

        android:duration="1000"/>

</set>


요렇게 하면 화면 가운데로 축소되는게 아니라 좌측 상단으로 축소된다..


<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate 

        android:fromXDelta="0"

        android:fromYDelta="0"

        android:toXDelta="50%"

        android:toYDelta="50%"

        android:duration="1000"/>

    <scale

        android:fromXScale="1"

        android:fromYScale="1"

        android:toXScale="0"

        android:toYScale="0"

        android:duration="1000"/>

</set>


그래서 요렇게 했는데.. 화면 중심으로 축소되는듯 하다가 좌측상단으로 축소되는 이상한 현상이...ㄷㄷㄷ


<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale

        android:fromXScale="1"

        android:fromYScale="1"

        android:toXScale="0"

        android:toYScale="0"

        android:duration="1000"/>

    <translate 

        android:fromXDelta="0"

        android:fromYDelta="0"

        android:toXDelta="50%"

        android:toYDelta="50%"

        android:duration="1000"/>

    <alpha 

        android:fromAlpha="1"

        android:toAlpha="0"

        android:duration="1000"/>

</set>


문제는 태그 위치였다.. scale 다음에 translate를 적용해야 한다.. 내부적인 이유겠지만..


그리고 alpha 를 적용하여 자연스럽게 사라지는 효과를 추가