Android Animationアニメーションシステム構造

7475 ワード

Androidアニメには、Property AnimationとView Animationの2種類があります。
reference:
http://developer.android.com/guide/topics/resources/animation-resource.html#Property
http://developer.android.com/guide/topics/graphics/prop-animation.html
一、Property Animation(属性アニメーション)
1.適用対象:view objectとnon-view object。
API Classサポート:android.animation
2.xmlファイルで実現し、res/animatorディレクトリの下に置いて参照します。
In Java:R.animtor.filename
In XML:@[package:]アニメイト/filename
3.xml文法スタイル:
<set
  android:ordering=["together" | "sequentially"]>

    <objectAnimator
        android:propertyName="string"
        android:duration="int"
        android:valueFrom="float | int | color"
        android:valueTo="float | int | color"
        android:startOffset="int"
        android:repeatCount="int"
        android:repeatMode=["repeat" | "reverse"]
        android:valueType=["intType" | "floatType"]/>

   <animator
        android:duration="int"
        android:valueFrom="float | int | color"
        android:valueTo="float | int | color"
        android:startOffset="int"
        android:repeatCount="int"
        android:repeatMode=["repeat" | "reverse"]
        android:valueType=["intType" | "floatType"]/>

    <set>
        ...
    </set>
</set>
4.Resource DataType
 Value Animer,Object Animator,orアニメイトSet.
xmlのラベルとの関係:
          -->   アニメイトセット
   -->   Objectアニメイト
<アニメイト/>          -->   Value Animation
ラベルには以上の3種類のラベルを入れることができます。
タグの中で、アンディロイド:orderingでアニメーションを順番に再生するか、それとも同時に再生するかを指定します。
5.簡単に使う
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
    R.anim.property_animator);
set.setTarget(myObject);
set.start();
6.reference
http://developer.android.com/guide/topics/resources/animation-resource.html#Property
二、View Animation(ビューアニメーション)
Viewアニメーションは、Tween animationとFrame animationの2つのタイプがあります。
Tweened animation is handed by this package(android.view.animation);frame-by-frame animation is handed by the Animation Drawable class.
reference:
http://developer.android.com/guide/topics/resources/animation-resource.html#View
http://developer.android.com/guide/topics/graphics/view-animation.html
(一)Tween animation
tweened animation、in which you tell Android to perform a series of simple transformation(position、size、rotation、and so on)to the content of a View.
1.適用対象:view object
API Classサポート:android.view.animation
2.xmlファイルで実現し、res/animディレクトリの下に置いて参照します。
In Java:R.anim.filename
In XML:@[package:]anim/filename
3.xml文法スタイル:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@[package:]anim/interpolator_resource"
    android:shareInterpolator=["true" | "false"] >
    <alpha
        android:fromAlpha="float"
        android:toAlpha="float" />
    <scale
        android:fromXScale="float"
        android:toXScale="float"
        android:fromYScale="float"
        android:toYScale="float"
        android:pivotX="float"
        android:pivotY="float" />
    <translate
        android:fromXDelta="float"
        android:toXDelta="float"
        android:fromYDelta="float"
        android:toYDelta="float" />
    <rotate
        android:fromDegrees="float"
        android:toDegrees="float"
        android:pivotX="float"
        android:pivotY="float" />
    <set>
        ...
    </set>
</set>
4.Resource DataType
 Animation Set、AlphaAnimation、ScaleAnimation、Translate Animation、RotateAnimation。
xmlのラベルとの関係:
      -->    アニメイトセット
<アルファ>          -->    アルファ動画
<scale>          -->    スクリーンアニメーション
<translate>      -->    Translate Animation
<rotate>         -->    RotateAnimation
ラベルには以上の5種類のラベルを入れることができます。
タグの中に重要な属性があります。android:interpolator.
5.簡単に使う
ImageView image = (ImageView) findViewById(R.id.image);
Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
image.startAnimation(hyperspaceJump);
6.reference
http://developer.android.com/guide/topics/resources/animation-resource.html#Tween
(二)Frame animation
frame-by-frame animation,which loads a series of Drawable resource one after the other.
1.適用対象:view object
API Classサポート:AnimationDrawable
2.xmlファイルで実現し、引用方式:res/drawable/filename.xml
In Java:R.drawable.filename
In XML:@[package:]drawable.filename
3.xml文法スタイル:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot=["true" | "false"] >
    <item
        android:drawable="@[package:]drawable/drawable_resource_name"
        android:duration="integer" />
</animation-list>
4.重要なラベル
ロトルートラベルとして、無数の「item」サブラベルが含まれています。android:oneshotで重複を指定します。
<item>は「animation-list」のラベルに含まれています。二つの属性:android:drawableとandroid:duration.
5.簡単に使う
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
6.reference
http://developer.android.com/guide/topics/resources/animation-resource.html#Frame
三、Property Animation(プロパティアニメーション)とView Animation(ビューアニメーション)の違い「How Property Animation Differs from View Animation」
The view animation system provides the capability to only animate View oject、so if you wanted to animate non-View oject、あなたのhave to implement your code to to do so.The view animation system stinesuch as the scaling and rotation of a View but not the backgroundカラー、for instance.
Another disadview of the view animation system is that only modified where the View drawn,and not the actual View itself.For instance,if You animed a button to moacros the screcture theso you have to implement your own logic to handle this.
With the property animation system,these constrants are compleetely removed,and you can animate any property of any oject(View and non-View)and the object it it is actually modified.The properia ansysあなたのassion、or size and can define aspects of the animation and synchronization of the animation Station and smultions.
The view animation system、however、taes less time to setup、requires less code to write.If view animation accompplishes everthat need to do、or if your existing code already works the wantthere isのneed to use the property animation system.It also might make sense to use both animation system for different situation s if the use case rises.
reference:
 http://developer.android.com/guide/topics/graphics/prop-animation.html#property-vs-view