Android動畫示例含代碼

Android動畫示例

Android提供了大量用于動畫開發的類和接口。愛掏網 - it200.com大部分類和接口都包含在 android.animation 包中。愛掏網 - it200.com

Android動畫使您能夠在運行時更改對象的屬性和行為。愛掏網 - it200.com在Android中有多種方式可以進行動畫操作。愛掏網 - it200.com

AnimationDrawable 類提供了啟動和停止動畫的方法。愛掏網 - it200.com甚至可以使用基于時間的動畫。愛掏網 - it200.com

讓我們來看一個簡單的Android動畫示例。愛掏網 - it200.com

activity_main.xml

只需要一個視圖。愛掏網 - it200.com

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <View
             />

</RelativeLayout>

只有圖片查看器。愛掏網 - it200.com

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/anm"
     >

</ImageView>

主Activity類

package com.javatpoint.animation;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;

public class MainActivity extends Activity {

    ImageView anm;
     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.logo);
            anm = (ImageView)findViewById(R.id.anm);

            anm.setBackgroundResource(R.drawable.animation);
        // the frame-by-frame animation defined as a xml file within the drawable folder

            /*
             * NOTE: It's not possible to start the animation during the onCreate.
             */
        }
     public void onWindowFocusChanged (boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            AnimationDrawable frameAnimation = 
                (AnimationDrawable) anm.getBackground();
            if(hasFocus) {
                frameAnimation.start();
            } else {
                frameAnimation.stop();
            }
        }

}

您需要在res/drawable-hdpi目錄下創建animation.xml文件。愛掏網 - it200.com

您需要有很多圖片。愛掏網 - it200.com在這里,我們使用了14個圖片,這14個圖片都位于res/drawable-mdpi目錄中。愛掏網 - it200.com

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false">

    <item android:drawable="@drawable/frame0" android:duration="120" />
    <item android:drawable="@drawable/frame1" android:duration="120" />
    <item android:drawable="@drawable/frame2" android:duration="120" />
    <item android:drawable="@drawable/frame3" android:duration="120" />
    <item android:drawable="@drawable/frame4" android:duration="120" />
    <item android:drawable="@drawable/frame5" android:duration="120" />
    <item android:drawable="@drawable/frame6" android:duration="120" />
    <item android:drawable="@drawable/frame7" android:duration="120" />
    <item android:drawable="@drawable/frame8" android:duration="120" />
    <item android:drawable="@drawable/frame9" android:duration="120" />
    <item android:drawable="@drawable/frame10" android:duration="120" />
    <item android:drawable="@drawable/frame11" android:duration="120" />
    <item android:drawable="@drawable/frame12" android:duration="120" />
    <item android:drawable="@drawable/frame13" android:duration="120" />
    <item android:drawable="@drawable/frame14" android:duration="120" />
    <item android:drawable="@drawable/frame14" android:duration="120" />
    <item android:drawable="@drawable/frame13" android:duration="120" />
    <item android:drawable="@drawable/frame12" android:duration="120" />
    <item android:drawable="@drawable/frame11" android:duration="120" />
    <item android:drawable="@drawable/frame10" android:duration="120" />
    <item android:drawable="@drawable/frame9" android:duration="120" />
    <item android:drawable="@drawable/frame8" android:duration="120" />
    <item android:drawable="@drawable/frame7" android:duration="120" />
    <item android:drawable="@drawable/frame6" android:duration="120" />
    <item android:drawable="@drawable/frame5" android:duration="120" />
    <item android:drawable="@drawable/frame4" android:duration="120" />
    <item android:drawable="@drawable/frame3" android:duration="120" />
    <item android:drawable="@drawable/frame2" android:duration="120" />
    <item android:drawable="@drawable/frame1" android:duration="120" />
    <item android:drawable="@drawable/frame0" android:duration="120" />

</animation-list>

輸出:

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論0 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 精品乱码久久久久久中文字幕 | 人妻无码一区二区三区AV| 品色堂永久免费| 久久久久亚洲av成人网| 麻豆国产精品有码在线观看| 欧美成年黄网站色视频| 国产精品美女久久久久AV福利| 国产三香港三韩国三级不卡 | 老师你的兔子好软水好多的车视频| 波多野结衣中文字幕一区二区三区 | 武则天一边上朝一边做h| 大地资源在线资源官网| 亚洲综合在线成人一区| 久热这里只精品99国产6_99| 色碰人色碰人视频| 淫术の馆在动漫在线播放| 在线观看欧美国产| 亚洲精品人成在线观看| 一本精品99久久精品77| 麻豆麻豆必出精品入口| 日韩一区二区三区电影| 国产一级第一级毛片| 中文字幕国产在线| 精品四虎免费观看国产高清午夜| 狠狠躁夜夜躁人人爽天天不卡软件| 日批免费观看视频| 又粗又大又爽又紧免费视频| www.天天射.com| 污污网站在线看| 国产精品jizzjizz| 久久青青草原亚洲av无码| 蜜桃臀无码内射一区二区三区| 日韩电影免费在线观看网| 国产乱妇乱子在线播放视频| 中文字幕日韩精品有码视频| 高清国产精品久久| 我和娇妻乱荡史| 亚洲色偷拍区另类无码专区| 搡女人免费免费视频观看| 日韩欧美福利视频| 又黄又爽视频好爽视频|