成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android使用Animation技巧講解

移動開發 Android
Android使用Animation的實現方法總共有兩種,一種為在xml中定義動畫的實現方法,另一種則是直接在代碼中定義動畫。

Android 使用Animation的具體操作方法我們將會在這篇文章中做一個詳細的介紹。大家可以通過這里舉出的代碼進行解讀,并從中了解到相關操作技巧,方便我們將來開發應用,并且加深對這一操作系統的理解程度。#t#

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

 

Android使用Animation方法一:在xml中定義動畫:

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 旋轉動畫效果   
  9. 屬性:interpolator 指定一個動畫的插入器,用來控制動畫的速度變化   
  10. fromDegrees 屬性為動畫起始時物件的角度   
  11. toDegrees 屬性為動畫結束時物件旋轉的角度,+代表順時針   
  12. duration 屬性為動畫持續時間,以毫秒為單位   
  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 旋轉動畫效果  
  23. 屬性:interpolator 指定一個動畫的插入器,用來控制動畫的速度變化  
  24. fromDegrees 屬性為動畫起始時物件的角度   
  25. toDegrees 屬性為動畫結束時物件旋轉的角度,+代表順時針  
  26. duration 屬性為動畫持續時間,以毫秒為單位  
  27. --> 
  28. < /set> 

 

使用動畫的Java代碼,程序的效果是點擊按鈕,TextView旋轉一周:

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方法二:直接在代碼中定義動畫(效果跟方法一類似):

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相關實現方法就為大家介紹到這里。

責任編輯:曹凱 來源: javaeye.com
相關推薦

2010-01-25 10:46:29

Android Spi

2010-01-11 16:04:10

VB.NET使用wit

2009-11-30 09:21:39

PHP函數rmdir(

2010-01-18 18:20:49

VB.NET使用API

2010-01-26 09:27:47

Android列表框

2010-02-24 13:48:44

MSMQ使用WCF

2010-01-28 16:55:26

Android對話框

2009-12-14 09:33:04

Ruby安裝

2009-12-25 17:39:01

WPF驗證

2009-12-14 15:30:43

安裝Ruby on R

2009-12-11 17:57:13

PHP應用JSON

2010-02-23 09:44:12

WCF dataCon

2022-07-11 11:58:28

VsCode技巧前端

2017-04-27 20:30:33

Android動畫技巧

2011-06-29 18:36:59

Qt 動畫 狀態機

2009-12-23 15:16:52

WPF數據綁定

2010-02-01 15:01:34

C++拋出異常

2009-12-10 17:37:28

PHP Cookie登

2010-02-22 16:19:25

WCF自托管

2009-12-30 18:18:32

Silverlight
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 色影视| 欧美一区二区三区免费电影 | 日韩精品一区二区三区中文字幕 | 久久国产精品-国产精品 | 国产精品一区二区在线观看 | 亚洲精品九九 | 日韩av电影院| 日韩成人在线视频 | 亚洲人久久 | 欧美黄色精品 | 日本网站免费观看 | 午夜在线| 精品不卡 | 亚洲最大的黄色网址 | 久久久91精品国产一区二区精品 | 成人国产精品一级毛片视频毛片 | 免费成人高清在线视频 | 国产一区亚洲二区三区 | 美女久久 | 97精品超碰一区二区三区 | 97视频人人澡人人爽 | 国产免费播放视频 | 国产精品久久久久久久久久免费看 | 日韩中字幕 | www.黄色网 | 一区二区三区中文字幕 | 久久精品91久久久久久再现 | 99这里只有精品视频 | 精品国产精品三级精品av网址 | 中文字幕亚洲精品 | 国产精品揄拍一区二区 | 亚洲成人一区 | 久久精品一级 | 第一区在线观看免费国语入口 | 欧美亚洲一区二区三区 | 亚洲综合在线一区二区 | 亚洲精品视频一区 | 日本字幕在线观看 | 午夜免费福利电影 | 91超碰caoporn97人人 | 国产日韩一区二区三免费高清 |