日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Android使用Animation技巧講解

Android 使用Animation的具體操作方法我們將會(huì)在這篇文章中做一個(gè)詳細(xì)的介紹。大家可以通過(guò)這里舉出的代碼進(jìn)行解讀,并從中了解到相關(guān)操作技巧,方便我們將來(lái)開(kāi)發(fā)應(yīng)用,并且加深對(duì)這一操作系統(tǒng)的理解程度。#t#

在Android中,分別可以在xml中定義Animation,也可以在程序代碼中定義,下面的小例子是利用RotateAnimation簡(jiǎn)單展示一下兩種Android使用Animation的方法,對(duì)于其他動(dòng)畫(huà),如ScaleAnimation,AlphaAnimation,原理是一樣的。

Android使用Animation方法一:在xml中定義動(dòng)畫(huà):

Xml代碼

 
 
 
  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < set xmlns:android=
    "http://schemas.android.com/apk/res/android">   
  3. < rotate   
  4. android:interpolator="@android:anim/accelerate_
    decelerate_interpolator"   
  5. android:fromDegrees="0"   
  6. android:toDegrees="+360"   
  7. android:duration="3000" />   
  8. < !-- rotate 旋轉(zhuǎn)動(dòng)畫(huà)效果   
  9. 屬性:interpolator 指定一個(gè)動(dòng)畫(huà)的插入器,用來(lái)控制動(dòng)畫(huà)的速度變化   
  10. fromDegrees 屬性為動(dòng)畫(huà)起始時(shí)物件的角度   
  11. toDegrees 屬性為動(dòng)畫(huà)結(jié)束時(shí)物件旋轉(zhuǎn)的角度,+代表順時(shí)針   
  12. duration 屬性為動(dòng)畫(huà)持續(xù)時(shí)間,以毫秒為單位   
  13. -->   
  14. < /set>   
  15. < ?xml version="1.0" encoding="utf-8"?> 
  16. < set xmlns:android=
    "http://schemas.android.com/apk/res/android"> 
  17. < rotate   
  18. android:interpolator=
    "@android:anim/accelerate_decelerate_interpolator" 
  19. android:fromDegrees="0"   
  20. android:toDegrees="+360" 
  21. android:duration="3000" /> 
  22. < !-- rotate 旋轉(zhuǎn)動(dòng)畫(huà)效果  
  23. 屬性:interpolator 指定一個(gè)動(dòng)畫(huà)的插入器,用來(lái)控制動(dòng)畫(huà)的速度變化  
  24. fromDegrees 屬性為動(dòng)畫(huà)起始時(shí)物件的角度   
  25. toDegrees 屬性為動(dòng)畫(huà)結(jié)束時(shí)物件旋轉(zhuǎn)的角度,+代表順時(shí)針  
  26. duration 屬性為動(dòng)畫(huà)持續(xù)時(shí)間,以毫秒為單位  
  27. --> 
  28. < /set> 

 

使用動(dòng)畫(huà)的Java代碼,程序的效果是點(diǎn)擊按鈕,TextView旋轉(zhuǎn)一周:

Java代碼

 
 
 
  1. package com.ray.animation;   
  2. import android.app.Activity;   
  3. import android.os.Bundle;   
  4. import android.view.View;   
  5. import android.view.View.OnClickListener;   
  6. import android.view.animation.Animation;   
  7. import android.view.animation.AnimationUtils;   
  8. import android.widget.Button;   
  9. import android.widget.TextView;   
  10. public class TestAnimation extends Activity 
    implements OnClickListener{   
  11. public void onCreate(Bundle savedInstanceState) {   
  12. super.onCreate(savedInstanceState);   
  13. setContentView(R.layout.main);   
  14. Button btn = (Button)findViewById(R.id.Button01);   
  15. btn.setOnClickListener(this);   
  16. }   
  17. @Override   
  18. public void onClick(View v) {   
  19. Animation anim = AnimationUtils.loadAnimation(this, 
    R.anim.my_rotate_action);   
  20. findViewById(R.id.TextView01).startAnimation(anim);   
  21. }   
  22. }   
  23. package com.ray.animation;  
  24. import android.app.Activity;  
  25. import android.os.Bundle;  
  26. import android.view.View;  
  27. import android.view.View.OnClickListener;  
  28. import android.view.animation.Animation;  
  29. import android.view.animation.AnimationUtils;  
  30. import android.widget.Button;  
  31. import android.widget.TextView;  
  32. public class TestAnimation extends Activity 
    implements OnClickListener{  
  33. public void onCreate(Bundle savedInstanceState) {  
  34. super.onCreate(savedInstanceState);  
  35. setContentView(R.layout.main);  
  36. Button btn = (Button)findViewById(R.id.Button01);  
  37. btn.setOnClickListener(this);   
  38. }  
  39. @Override  
  40. public void onClick(View v) {  
  41. Animation anim = AnimationUtils.loadAnimation(this, 
    R.anim.my_rotate_action);  
  42. findViewById(R.id.TextView01).startAnimation(anim);  
  43. }  

 

Android使用Animation方法二:直接在代碼中定義動(dòng)畫(huà)(效果跟方法一類(lèi)似):

Java代碼

 
 
 
  1. package com.ray.animation;   
  2. import android.app.Activity;   
  3. import android.os.Bundle;   
  4. import android.view.View;   
  5. import android.view.View.OnClickListener;   
  6. import android.view.animation.AccelerateDecelerateInterpolator;   
  7. import android.view.animation.Animation;   
  8. import android.view.animation.RotateAnimation;   
  9. import android.widget.Button;   
  10. public class TestAnimation extends Activity 
    implements OnClickListener{   
  11. public void onCreate(Bundle savedInstanceState) {   
  12. super.onCreate(savedInstanceState);   
  13. setContentView(R.layout.main);   
  14. Button btn = (Button)findViewById(R.id.Button);   
  15. btn.setOnClickListener(this);   
  16. }   
  17. public void onClick(View v) {   
  18. Animation anim = null;   
  19. anim = new RotateAnimation(0.0f,+360.0f);   
  20. anim.setInterpolator(new AccelerateDecelerateInterpolator());   
  21. anim.setDuration(3000);   
  22. findViewById(R.id.TextView01).startAnimation(anim);   
  23. }   

Android使用Animation相關(guān)實(shí)現(xiàn)方法就為大家介紹到這里。


網(wǎng)站標(biāo)題:Android使用Animation技巧講解
文章網(wǎng)址:http://www.dlmjj.cn/article/dphodie.html