android-Animation-十二
1Animations
?? 它是指顯示的動畫效果,這些效果可以應用在絕大多數的控件里。
2Animations的分類
? 第一類:Tweened Animations
???????????? 該類Animations提供了旋轉(RotateAnimation),移動(TranslateAnimation),伸展(ScaleAnimation)
?????????????和談出(AlphaAnimation)的效果。Animation抽象類下的五大子類:
????????????? AlphaAnimation,?AnimationSet,?RotateAnimation,?ScaleAnimation,?TranslateAnimation
?????????????其中AnimationSet的是用來裝載多個其他的Animation,這樣一個控件可以顯示多個動畫效果。
? 第二類:Frame-by-Frame Animations
???????????? 這一類Animations可以創建一個Drawable序列,這些Drawable可以按照指定的時間間隙一個一個的顯示
3.Tweened Animations使用
??? 1.創建一個AnimationSet對象。
??? 2.創建(一個或多個)Animation對象(即除了Set以外的)。
??? 3.設置Animation對象的屬性,AnimationSet屬性。
??? 4.調用控件的方法startAnimation(animtion);//該控件就是要使用動畫效果的控件
1 public class AnimationTestActivity extends Activity { 2 3 /*animation:動畫演示 4 * 1.創建AnimationSet 5 * 2.創建Animation對象: 6 * AlphaAnimation, RotateAnimation, 7 * ScaleAnimation, TranslateAnimation 8 * 3.設置該對象的參數 9 * 4.set添加該對象進去 10 * 5.使用控件對象執行set 11 * */ 12 private Button alphabutton=null; 13 private Button rotatebutton=null; 14 private Button scalebutton=null; 15 private Button translatebutton=null; 16 private ImageView imageview=null; 17 /** Called when the activity is first created. */ 18 @Override 19 public void onCreate(Bundle savedInstanceState) { 20 super.onCreate(savedInstanceState); 21 setContentView(R.layout.main); 22 alphabutton=(Button)findViewById(R.id.alphabutton); 23 rotatebutton=(Button)findViewById(R.id.rotatebutton); 24 scalebutton=(Button)findViewById(R.id.scalebutton); 25 translatebutton=(Button)findViewById(R.id.translatebutton); 26 imageview=(ImageView)findViewById(R.id.imageview); 27 alphabutton.setOnClickListener(new OnClickListener() { 28 29 public void onClick(View v) { 30 // TODO Auto-generated method stub 31 //1.創建AnimationSet對象 32 AnimationSet set=new AnimationSet(true); 33 //2.創建alphaanimation對象 34 AlphaAnimation aa=new AlphaAnimation(1, 0); 35 aa.setDuration(1000); 36 //3.添加進去 37 set.addAnimation(aa); 38 //4.控件啟動該set 39 imageview.startAnimation(set); 40 } 41 }); 42 rotatebutton.setOnClickListener(new OnClickListener() { 43 44 public void onClick(View v) { 45 // TODO Auto-generated method stub 46 //1.創建AnimationSet對象 47 AnimationSet set=new AnimationSet(true); 48 //2.創建alphaanimation對象 49 RotateAnimation aa=new RotateAnimation(70,0,70,0); 50 set.setDuration(1000); 51 set.setFillAfter(true); 52 set.setFillBefore(false); 53 //3.添加進去 54 set.addAnimation(aa); 55 //4.控件啟動該set 56 imageview.startAnimation(set); 57 } 58 }); 59 60 } 61 } View Code4.Frame-by-Frame Animations使用
?? res/anim/目錄下的animationset的xml文件
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"><alpha android:fromAlpha="0.1"android:toAlpha="1.0"android:duration="3000"/> <rotateandroid:fromDegrees="0"android:toDegrees="360"android:pivotX="0.5"android:pivotY="0.5"android:duration="3000"/> </set> public class AnimationTest2Activity extends Activity {/** 使用自定義的Animation*/private Button alphabutton=null;private ImageView imageview=null;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);alphabutton=(Button)findViewById(R.id.alphabutton);imageview=(ImageView)findViewById(R.id.imageview);alphabutton.setOnClickListener(new OnClickListener() {public void onClick(View v) {//1.獲得alphaanimationset對象,R.anim.alpha為我們創建的alphaanimationset的xml文件Animation autils= AnimationUtils.loadAnimation(AnimationTest2Activity.this,R.anim.alpha);//2.控件啟動該set imageview.startAnimation(autils);}});} }5.Interpolator和視頻效果(采用多張圖片快速顯示)
轉載于:https://www.cnblogs.com/beyondbycyx/p/4297344.html
總結
以上是生活随笔為你收集整理的android-Animation-十二的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Html的空格显示
- 下一篇: ios UIScrollView 中控