Skip to content

Android:ViewAnimation

Animation 리소스의 사용

안드로이드에서는 animation도 resource로 등록이 된다. 프로젝트 폴더\res\anim\폴더 밑에 XML형식의 문서로 저장되며, Java 에서는 AnimationUtil:loadAnimation(context, int)을 이용해 컴파일된 animation 리소스에 접근한다. 1

XML 문서에서 사용되는 주요 XML Element와 Attribute는 다음과 같다.

  • <translate>
    • 상하좌우 이동 animation을 지정하며. TranslateAnimation 클래스에 대응한다.
    • 다음과 같은 4가지의 xml attribute에
      • android:fromXDelta: animation시작하는 X 좌표
      • android:toXDelta: 끝나는 X 좌표
      • android:fromYDelta: Starting Y location.
      • android:toYDelta: Ending Y location.
    • 다음과 같은 3가지 종류의 값(value) 중 하나를 사용한다.
      • -100% ~ 100%: 자기자신을 기준으로 한 위치에 대한 비율. 0%가 현재 자기 위치.
      • -100%p ~ 100%p: 부모 컨테이너를 기준으로 한 위치에 대한 비율. 0%p가 현재 자기 위치.
      • float값: 절대 위치를 나타냄.
  • <alpha>
    • 투명함을 조정하며, AlphaAnimation 클래스에 대응한다.
    • 다음과 같은 xml attribute를
      • android:fromAlpha: animation 시작 시 투명도
      • android:toAlpha: animation 완료 시 투명도
    • 다음과 같은 값으로 설정한다.
      • 0.0 ~ 1.0 (0.0이 투명, 1.0이 완전 불 투명)

추가로 위의 두 element(translate, alpha)에서 공통으로 사용되는 animation이 지속되는 시간을 나타내는 attribute는 다음과 같다.

  • android:duration: Animnation이 시작돼서 끝나는 시간을 밀리 초(1/1000초) 단위로 설정함.

Favorite site

References


  1. 'R.anim.animation_xml_file_이름' 이용