自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android ApiDemo示例解讀3:App->Activity->Animation

移動(dòng)開發(fā) Android
SDK中的示例程序App->Activity->Animation演示了切換Activity時(shí)的動(dòng)畫效果。提供了兩種動(dòng)畫效果,一種是Fade In漸變,后出現(xiàn)的Activity由淺入深逐漸顯示;另一種是Zoom放大效果,后出現(xiàn)的Activity由小及大逐漸顯示。

SDK中的示例程序App->Activity->Animation演示了切換Activity時(shí)的動(dòng)畫效果。提供了兩種動(dòng)畫效果,一種是Fade In漸變,后出現(xiàn)的Activity由淺入深逐漸顯示;另一種是Zoom放大效果,后出現(xiàn)的Activity由小及大逐漸顯示。

Android 中 Animation 資源可以分為兩種:

Tween Animation 對(duì)單個(gè)圖像進(jìn)行各種變換(縮放,平移,旋轉(zhuǎn)等)來(lái)實(shí)現(xiàn)動(dòng)畫。

Frame Animation 由一組圖像順序顯示顯示動(dòng)畫。

Animation 中使用的是Tween Animation,使用的資源為R.anim.fade、R.anim.hold、R.anim.zoom_enter、R.anim.zoom_exit。

其中R.anim.fade、R.anim.zoom_enter分別為Fade In 和 Zoom動(dòng)畫資源。其定義為:

fade.xml

  1. <alpha xmlns:android=”http://schemas.android.com/apk/res/android”    
  2. android:interpolator=”@android:anim/accelerate_interpolator”    
  3. android:fromAlpha=”0.0″ android:toAlpha=”1.0″    
  4. android:duration=”@android:integer/config_longAnimTime” />   

zoom_center.xml

  1. <set xmlns:android=”http://schemas.android.com/apk/res/android”    
  2. android:interpolator=”@android:anim/decelerate_interpolator”>   
  3. <scale android:fromXScale=”2.0″ android:toXScale=”1.0″    
  4.  android:fromYScale=”2.0″ android:toYScale=”1.0″    
  5.  android:pivotX=”50%p” android:pivotY=”50%p”    
  6.  android:duration=”@android:integer/config_mediumAnimTime” />   
  7. </set>   

tween animation 資源定義的格式如下:

  1. <?xml version=”1.0″ encoding=”utf-8″?>   
  2.  <set xmlns:android=”http://schemas.android.com/apk/res/android”    
  3.  android:interpolator=”@[package:]anim/interpolator_resource”    
  4.  android:shareInterpolator=[ ” true ” false “>   
  5.  <alpha   
  6.  android:fromAlpha=”float”    
  7.  android:toAlpha=”float” />   
  8.  <scale   
  9.  android:fromXScale=”float”    
  10.  android:toXScale=”float”    
  11.  android:fromYScale=”float”    
  12.  android:toYScale=”float”    
  13.  android:pivotX=”float”    
  14.  android:pivotY=”float” />   
  15.  <translate   
  16.  android:fromXDelta=”float”    
  17.  android:toXDelta=”float”    
  18.  android:fromYDelta=”float”    
  19.  android:toYDelta=”float” />   
  20.  <rotate   
  21.  android:fromDegrees=”float”    
  22.  android:toDegrees=”float”    
  23.  android:pivotX=”float”    
  24.  android:pivotY=”float” />   
  25.  <set> …    
  26.  </set>   
  27.  </set>   

<set> 為其它animation類型<alpha>,<scale>,<translate>和<rotate>或其它<set>的容器。

android:interpolator 為Interpolator資源ID,Interpolator定義了動(dòng)畫的變化速率,動(dòng)畫的各幀的顯示可以加速,減速,重復(fù)顯示。

android:shareInterpolator 如果想為<set>中的各個(gè)子動(dòng)畫定義共享interpolator,shareInterpolator 則設(shè)為true。

<alpha> 定義Fade in 、Fade out 動(dòng)畫,其對(duì)應(yīng)的Android類AlphaAnimation,參數(shù)由fromAlpha,toAlpha定義。

<scale>定義縮放動(dòng)畫,其對(duì)應(yīng)的Android類為ScaleAnimation,參數(shù)由fromXScale、toXScale、 fromYScale、toYScale、pivotX、pivotY定義,pivotX、pivotY定義了縮放時(shí)的中心。

<translate>定義平移動(dòng)畫,其對(duì)應(yīng)的Android類為TranslateAnimation,參數(shù)由fromXDelta、toXDelta、fromYDelta、toYDelta定義。

<rotate>定義選擇動(dòng)畫,其對(duì)應(yīng)的Android類RotateAnimation,參數(shù)由fromDegrees、toDegrees、pivotX、pivotY, pivotX、pivotY定義選擇中心。

Animation中的Fade In和Zoom In按鈕的事件處理代碼:

  1. private OnClickListener mFadeListener = new OnClickListener() {    
  2.  public void onClick(View v) {    
  3.  // Request the next activity transition (here starting a new one).    
  4.  startActivity(new Intent(Animation.this, Controls1.class));    
  5.  // Supply a custom animation.  This one will just fade the new    
  6.  // activity on top.  Note that we need to also supply an animation    
  7.  // (here just doing nothing for the same amount of time) for the    
  8.  // old activity to prevent it from going away too soon.    
  9.  overridePendingTransition(R.anim.fade, R.anim.hold);    
  10.  }    
  11. };   
  12. private OnClickListener mZoomListener = new OnClickListener() {    
  13.  public void onClick(View v) {    
  14.  // Request the next activity transition (here starting a new one).    
  15.  startActivity(new Intent(Animation.this, Controls1.class));    
  16.  // This is a more complicated animation, involving transformations    
  17.  // on both this (exit) and the new (enter) activity.  Note how for    
  18.  // the duration of the animation we force the exiting activity    
  19.  // to be Z-ordered on top (even though it really isn't) to achieve    
  20.  // the effect we want.    
  21.  overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);    
  22.  }    
  23. };   

從代碼可以看到Activity Animation到其它Activity Controls1 切換的動(dòng)畫使用overridePendingTransition 來(lái)定義,函數(shù)overridePendingTransition(int enterAnim, int exitAnim) 必須定義在StartActivity(Intent) 或是 Activity.finish()之后來(lái)定義兩個(gè)Activity切換時(shí)的動(dòng)畫,enterAnim 為新Activity出現(xiàn)時(shí)動(dòng)畫效果,exitAnim則定義了當(dāng)前Activity退出時(shí)動(dòng)畫效果。

責(zé)任編輯:閆佳明 來(lái)源: jizhuomi
相關(guān)推薦

2013-12-19 14:28:04

Android ApiAndroid開發(fā)Android SDK

2013-12-19 14:32:31

Android ApiAndroid開發(fā)Android SDK

2013-12-19 14:34:52

Android ApiAndroid開發(fā)Android SDK

2013-12-19 14:36:43

Android ApiAndroid開發(fā)Android SDK

2013-12-19 14:13:16

Android ApiAndroid開發(fā)Android SDK

2013-12-19 14:16:46

Android ApiAndroid開發(fā)Android SDK

2013-12-19 13:40:44

Android ApiAndroid開發(fā)Android SDK

2013-12-19 13:51:12

Android ApiAndroid開發(fā)Android SDK

2013-12-19 16:26:29

Android ApiAndroid開發(fā)Android SDK

2010-02-02 14:22:50

Python示例

2010-01-28 13:12:47

Android使用An

2014-05-27 14:16:08

AndroidActivitysingleTask

2010-02-01 11:22:09

C++虛函數(shù)

2019-07-19 10:44:34

移動(dòng)應(yīng)用APP

2010-03-02 14:41:00

WCF行為控制

2010-03-05 10:47:05

Python futu

2013-01-08 13:33:07

Android開發(fā)Activity入門指南

2010-02-04 16:07:39

C++回調(diào)函數(shù)

2010-01-04 17:03:27

Silverlight

2015-10-20 15:54:16

android源碼滑動(dòng)關(guān)閉
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)