日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Android 動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)

 greenyun588 2013-09-14

    補(bǔ)間動(dòng)畫(huà)是指定開(kāi)始和結(jié)束的圖像狀態(tài),自動(dòng)生成需要顯示的過(guò)度圖像的動(dòng)畫(huà)。補(bǔ)間動(dòng)畫(huà)又分為四種:移動(dòng),縮放,旋轉(zhuǎn),通明度。下面以移動(dòng)補(bǔ)間動(dòng)畫(huà)來(lái)做簡(jiǎn)單說(shuō)明,效果是把一個(gè)ImageView從左上角,向右下方向移動(dòng),然后返回到起始點(diǎn),中間對(duì)動(dòng)畫(huà)狀態(tài)進(jìn)行監(jiān)聽(tīng),效果如圖:




 


    下面簡(jiǎn)述其主要步驟:


 


    1、定義動(dòng)畫(huà)文件:


Java代碼 復(fù)制代碼 收藏代碼
  1. <translate xmlns:android="http://schemas./apk/res/android"    
  2.     android:duration="5000"    
  3.     android:fromXDelta="0"    
  4.     android:fromYDelta="0"    
  5.     android:interpolator="@android:anim/accelerate_decelerate_interpolator"    
  6.     android:toXDelta="200"    
  7.     android:toYDelta="300" />    

 說(shuō)明:



  • android:interpolator:動(dòng)畫(huà)渲染器,有三種渲染器可以設(shè)
    置:accelerate_decelerate_interpolator,accelerate_interpolator,decelerate_interpolator,
    它們分別對(duì)應(yīng)的效果是:開(kāi)始加速中間減速,一直加速,一直減速。

  • fromXDelta;動(dòng)畫(huà)起始位置的X坐標(biāo);

  • fromYDelta:動(dòng)畫(huà)起始位置的Y坐標(biāo);

  • toXDelta:動(dòng)畫(huà)結(jié)束位置的X坐標(biāo);

  • toYDelta:動(dòng)畫(huà)結(jié)束位置的Y坐標(biāo);

  • duration:動(dòng)畫(huà)持續(xù)時(shí)間,單位毫秒。


    2、加載并啟動(dòng)動(dòng)畫(huà):


Java代碼 復(fù)制代碼 收藏代碼
  1. import android.app.Activity;  
  2. import android.os.Bundle;  
  3. import android.util.Log;  
  4. import android.view.animation.Animation;  
  5. import android.view.animation.AnimationUtils;  
  6. import android.view.animation.Animation.AnimationListener;  
  7. import android.widget.ImageView;  
  8.   
  9. public class TranslateActivity extends Activity implements AnimationListener {  
  10.       
  11.     private static final String TAG = "Translate";  
  12.       
  13.     private ImageView imageView;  
  14.     private Animation translateAnimation;  
  15.       
  16.     /** Called when the activity is first created. */  
  17.     @Override  
  18.     public void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.main);  
  21.           
  22.         imageView = (ImageView) findViewById(R.id.imageView1);  
  23.           
  24.         // 裝載動(dòng)畫(huà)文件  
  25.         translateAnimation = AnimationUtils.loadAnimation(this, R.xml.translate);  
  26.           
  27.         // 設(shè)置動(dòng)畫(huà)監(jiān)聽(tīng)器  
  28.         translateAnimation.setAnimationListener(this);  
  29.           
  30.         // 設(shè)置重復(fù)次數(shù)  
  31.         translateAnimation.setRepeatCount(1);  
  32.           
  33.         // 設(shè)置重復(fù)模式  
  34.         translateAnimation.setRepeatMode(Animation.REVERSE);  
  35.           
  36.         // 啟動(dòng)動(dòng)畫(huà)  
  37. //        imageView.setAnimation(translateAnimation);  
  38. //        translateAnimation.start();  
  39.           
  40.         imageView.startAnimation(translateAnimation);  
  41.           
  42.     }  
  43.   
  44.     @Override  
  45.     public void onAnimationEnd(Animation animation) {  
  46.         Log.i(TAG, "onAnimationEnd");  
  47.     }  
  48.   
  49.     @Override  
  50.     public void onAnimationRepeat(Animation animation) {  
  51.         Log.i(TAG, "onAnimationRepeat");  
  52.     }  
  53.   
  54.     @Override  
  55.     public void onAnimationStart(Animation animation) {  
  56.         Log.i(TAG, "onAnimationStart");  
  57.     }  
  58.       
  59. }  

    修改上面的某些代碼,猜想效果,并和實(shí)際效果作對(duì)比,有時(shí)會(huì)發(fā)現(xiàn)很有趣的現(xiàn)象!:)


 


    縮放動(dòng)畫(huà)的XML示例代碼:


 


Java代碼 復(fù)制代碼 收藏代碼
  1. <set xmlns:android="http://schemas./apk/res/android"  
  2.     android:shareInterpolator="false" >  
  3.   
  4.     <scale  
  5.         android:duration="500"  
  6.         android:fromXScale="1"  
  7.         android:fromYScale="0.1"  
  8.         android:pivotX="50%"  
  9.         android:pivotY="50%"  
  10.         android:startOffset="100"  
  11.         android:toXScale="1"  
  12.         android:toYScale="1.0" />  
  13.   
  14. </set>  

 


    旋轉(zhuǎn)動(dòng)畫(huà)的XML示例代碼如下:


Java代碼 復(fù)制代碼 收藏代碼
  1. <rotate xmlns:android="http://schemas./apk/res/android"  
  2.     android:duration="10000"  
  3.     android:fromDegrees="0"  
  4.     android:interpolator="@anim/linear_interpolator"  
  5.     android:pivotX="200%"  
  6.     android:pivotY="300%"  
  7.     android:repeatCount="infinite"  
  8.     android:repeatMode="restart"  
  9.     android:toDegrees="360" />  

 


    3、多說(shuō)一句:


    使用代碼同樣可以實(shí)現(xiàn)從XML加載動(dòng)畫(huà)一樣的效果,有興趣的話,可以試試看?。海?/p>

 


 


 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多