ノート28--アニメーション

3783 ワード

みんなに原文を読むように勧めます。http://blog.csdn.net/singwhatiwanna/article/details/17841165以下の内容の90%はここからです。
androidアニメーションは3つの種類に分けられます。
1、Tween Animation:シーンのオブジェクトを常に変換(平行移動、拡大縮小、回転、透明度)することによって、アニメーション効果が発生します。つまり、グラデーションアニメーションです。
2、Frame Animation:事前に作った画像を順番に再生する画面変換アニメーションです。
3、Property Animation:属性アニメーションは、オブジェクトの属性を動的に変えてアニメーション効果を達成し、属性アニメーションはAPI 11の新しい特性を持っていない。
一、Tween Animation:
四種類の形式:
XML中:1)アルファ:グラデーション透明度アニメーション効果。2)スケール:グラデーションサイズの伸縮アニメーション効果。3)トレイ:画面位置移動動画効果。4)rotate:画面回転動画効果。
JAVA中:1)Alpha Animation。2)ScaleAnimation。3)Translate Animation。4)RotateAnimation。意味を同じくする
実装方法は2つあります。1)xml+java方式 2)java方式
1)xml+java:xmlでアニメーション効果を定義し、javaでアニメーションを開始します。
<?xml version="1.0" encoding="utf-8"?>  
  
<set xmlns:android="http://schemas.android.com/apk/res/android"  
    android:fillAfter = "false"  
    android:zAdjustment="bottom"  
    >  
    <rotate  
        android:fromDegrees="0"  
        android:toDegrees="360"  
        android:pivotX="50%"  
        android:pivotY="50%"  
        android:duration="4000"  
        />  
</set>
Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.rotate);  
  
//       (  ,  )  
anim.setAnimationListener(new EffectAnimationListener());  
textWidget = (TextView)findViewById(R.id.text_widget);  
textWidget.setText("        ");  
textWidget.startAnimation(anim);  
2)java:
RotateAnimation myAnimation_Rotate;
//     fromDegrees               
//     toDegrees            
//     pivotXValue         X        
//     pivotYValue         Y       
myAnimation_Rotate=new RotateAnimation(0.0f, +360.0f,
	Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
myAnimation_Rotate.setDuration(3000);

TextView textWidget = (TextView)findViewById(R.id.text_widget);  
textWidget.setText("        ");
textWidget.startAnimation(myAnimation_Rotate);
アニメフォルダの下に新しいxmlを作成します。
属性紹介:共通のいくつか:duration、repeat Count、repeat Mode
1)rotate(回転):支点を探して、この支点を基準にして、1度から別の度に回転します。ピvot:支点、枢軸
2)アルファ(透明度):開始透値範囲が0.0-1.0未満
3)scale:値が0-1の場合は縮小の倍数を指し、1より大きい場合は拡大の倍数を指す。
4)translate(シフト):デルタ:シフトの増分
二、Frame Animation
アニメイトパッケージとは違って、Android SDKはもう一つの種類のAnimation Drawableを提供してFrame Animationを定義します。
<?xml version="1.0" encoding="utf-8"?>  
  
<animation-list  
  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:oneshot="true"  
  >  
       <item android:drawable="@drawable/p1" android:duration="1000"></item>  
       <item android:drawable="@drawable/p2" android:duration="1000"></item>  
       <item android:drawable="@drawable/p3" android:duration="1000"></item>  
       <item android:drawable="@drawable/p4" android:duration="1000"></item>  
       <item android:drawable="@drawable/p5" android:duration="1000"></item>  
       <item android:drawable="@drawable/p6" android:duration="1000"></item>  
</animation-list>
AnimationDrawable anim = (AnimationDrawable)getResources().  
	getDrawable(R.drawable.frame);  
TextView textWidget = (TextView)findViewById(R.id.text_widget); 
textWidget = (TextView)findViewById(R.id.text_widget);  
textWidget.setText("        ");  
textWidget.setBackground(anim);  
anim.start();
drawableフォルダの下に、animation-listを新規作成します。
属性紹介:xmlには複数のitemタブのみが含まれています。属性はdurationとdrawableが含まれています。