在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Android Animation(動畫)實例
Android 應(yīng)用組件
使用布局文件自定義Android組件
Android通知
Android主題示例
Android JetPlayer實例
Android MediaPlayer(多媒體播放)
Android AbsoluteLayout
Android FrameLayout
Android Gestures/手勢
Android AutoCompleteTextView(自動完成)實例
Android 資源組織和訪問
Android ListView
Android GridView
Android數(shù)據(jù)備份
Android撥打電話
Android發(fā)送短信/SMS
Android ProgressDialog
SimpleCursorAdapter
Android發(fā)送電子郵件
Android Activity
Android TextView
Android事件處理
Android TableLayout
Android加載Spinner
Android內(nèi)容提供者
Android自定義字體
Android Service
Android CheckBox
Android Intent過濾器
Android LinearLayout
Android登錄實例
Android RadioButton
Android樣式和主題
Android自定義組件及屬性
Android UI控件
Android Animation(動畫)實例
Android Camera(攝像頭)
Android ToggleButton
Android Clipboard(復(fù)制/剪貼板)
Android音頻捕獲(錄音)
發(fā)布Android應(yīng)用
Android Alertdialog(警告對話框)
Android圖片效果
Android內(nèi)部存儲
Android基于位置服務(wù)
Android RadioGroup
Android AutoCompleteTextView
Android Bluetooth(藍牙)實例
Android RelativeLayout
Android最佳實踐
Android本地化
Android自定義組件
Android教程
Android 架構(gòu)
Android UI布局
Android Button
Android Hello World示例
Android音頻管理器實例
ArrayAdapter
Android拖放
Android碎片/片段
Android圖片切換
Android JSON解析器
Android開發(fā)環(huán)境搭建
Android Spinner
Android樣式示例
使用活動代碼自定義Android組件
Android ImageButton
Android EditText
Android廣播接收器

Android Animation(動畫)實例

動畫在Android中可以有許多方式。在本章中,我們將討論一個簡單的和廣泛使用的動畫制作 - 所謂的補間動畫方式。

補間動畫

補間動畫需要一些參數(shù),如初始值,終值,大小,持續(xù)時間,旋轉(zhuǎn)角度等,并對該對象執(zhí)行所需的動畫。它可以應(yīng)用到任何類型的對象。因此,為了利用這一點,Android已經(jīng)為我們提供了一個類叫做 Animation.

為了在android系統(tǒng)進行顯示動畫,我們將調(diào)用AnimationUtils 類的靜態(tài)函數(shù) loadAnimation()。我們將接受它在動畫對象的實例。它的語法如下:

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);

注意第二個參數(shù)。它是動畫 xml文件的名稱。必須創(chuàng)建一個res目錄下名為anim的文件夾,并在anim文件夾中創(chuàng)建XML文件。

這個動畫 animation 類有下面列出許多有用的功能:

Sr.No 方法 & 描述
1 start()
此方法開始動畫
2 setDuration(long duration)
此方法設(shè)置動畫的持續(xù)時間
3 getDuration()
此方法獲得其通過上述方法設(shè)定的持續(xù)時間
4 end()
此方法結(jié)束動畫
5 cancel()
這個方法取消動畫

為了應(yīng)用這個動畫到對象,我們將只調(diào)用對象的startAnimation()方法。其語法是:

ImageView image1 = (ImageView)findViewById(R.id.imageView1);
image.startAnimation(animation);

放大動畫

為了在動畫進行縮放,下創(chuàng)建anim文件夾中XML文件在res目錄下,并把這個代碼的文件中。

<set xmlns:android="http://schemas.android.com/apk/res/android">

   <scale xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromXScale="0.5"
      android:toXScale="3.0"
      android:fromYScale="0.5"
      android:toYScale="3.0"
      android:duration="5000"
      android:pivotX="50%"
      android:pivotY="50%" >

   </scale>

</set>

參數(shù) fromXScale、fromYScale 限定開始點和參數(shù) toXScale、toYScale定義結(jié)束點。duration 定義了動畫的時間和pivotX,pivotYdefines中心從其中動畫將開始。

例子

參數(shù) fromXScale、fromYScale限定開始點,參數(shù) toXScale、toYScale 定義結(jié)束點。duration 定義了動畫的時間 pivotX,pivotY 定義的中心從其中動畫將開始。

為了試驗這個例子,需要在模擬器或?qū)嶋H設(shè)備上運行。

Steps 描述
1 使用Android Studio創(chuàng)建Android應(yīng)用程序,并將其命名為Animation ,創(chuàng)建這個項目時確保目標(biāo)SDK編譯在Android SDK的最新版本并使用更高級別的API
2 修改src/MainActivity.java文件中添加動畫代碼
3 修改所需的布局XML文件res/layout/activity_main.xml l添加GUI組件
4 res目錄下新建一個文件夾,并將其命名為anim。通過訪問確認(rèn):res/anim
5 創(chuàng)建新的Android XML文件,必須創(chuàng)建下面列出了三種不同的文件
6 創(chuàng)建myanimation.xml,clockwise.xml,fade.xml文件并添加XML代碼
7 修改 res/values/string.xml 文件,并添加必要的字符串組成部分
8 修改res/menu/main.xml文件,并添加必要的菜單組件
9 運行應(yīng)用程序并選擇要運行的Android設(shè)備,并在其上安裝的應(yīng)用和驗證結(jié)果。

這里是修改后的代碼 src/com.yii bai.animation/MainActivity.java.

package com.example.animation;

import com.example.animation.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
   }

   public boolean onOptionsItemSelected(MenuItem item) 
   { 
   super.onOptionsItemSelected(item); 
      switch(item.getItemId()) 
      { 
      case R.id.zoomInOut:
         ImageView image = (ImageView)findViewById(R.id.imageView1);
         Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);
         image.startAnimation