Android之AnimationDrawable簡(jiǎn)單模擬動(dòng)態(tài)圖
Drawable animation可以加載Drawable資源實(shí)現(xiàn)幀動(dòng)畫(huà)。AnimationDrawable是實(shí)現(xiàn)Drawable animations的基本類(lèi)。
這里用AnimationDrawable 簡(jiǎn)單模擬動(dòng)態(tài)圖的實(shí)現(xiàn)。
fragment_main 布局文件 ---- 只需要放一個(gè) ImageView即可
<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"
tools:context="com.yztc.frameanimation.MainActivity" >
<ImageView
android:id="@+id/iv_frame"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/girl_and_boy" />
</RelativeLayout>
girl_and_boy 布局文件 ---- 實(shí)現(xiàn)動(dòng)畫(huà)
推薦用XML文件的方法實(shí)現(xiàn)Drawable動(dòng)畫(huà),不推薦在代碼中實(shí)現(xiàn)。這種XML文件存放在工程中res/drawable/目錄下。XML文件的指令(即屬性)為動(dòng)畫(huà)播放的順序和時(shí)間間隔。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- onshot 屬性表示動(dòng)畫(huà)只執(zhí)行一次 -->
<!-- duration 表示持續(xù)時(shí)間 -->
<item
android:drawable="@drawable/girl_1"
android:duration="200">
</item>
<item
android:drawable="@drawable/girl_2"
android:duration="200">
</item>
<item
android:drawable="@drawable/girl_3"
android:duration="200">
</item>
<item
android:drawable="@drawable/girl_4"
android:duration="200">
</item>
<item
android:drawable="@drawable/girl_5"
android:duration="300">
</item>
<item
android:drawable="@drawable/girl_6"
android:duration="400">
</item>
<item
android:drawable="@drawable/girl_7"
android:duration="500">
</item>
<item
android:drawable="@drawable/girl_8"
android:duration="400">
</item>
<item
android:drawable="@drawable/girl_9"
android:duration="300">
</item>
<item
android:drawable="@drawable/girl_10"
android:duration="200">
</item>
<item
android:drawable="@drawable/girl_11"
android:duration="200">
</item>
</animation-list>
MainActivity
package com.dragon.android.initgif;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
ImageView ivFrame = (ImageView) findViewById(R.id.iv_frame);
// 得到一個(gè)動(dòng)畫(huà)圖片
AnimationDrawable background = (AnimationDrawable) ivFrame
.getBackground();
// 開(kāi)始播放
background.start();
// 停止方法.
// background.stop();
}
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 本地廣播和強(qiáng)制下線功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 本地廣播和強(qiáng)制下線功能的實(shí)現(xiàn)代碼,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
關(guān)于gradle你應(yīng)該知道的一些小事
這篇文章主要給大家介紹了關(guān)于gradle你應(yīng)該知道的一些小事,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用gradle具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
Retrofit源碼之請(qǐng)求對(duì)象的轉(zhuǎn)換筆記
這篇文章主要介紹了Retrofit源碼之請(qǐng)求對(duì)象的轉(zhuǎn)換筆記,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
Android開(kāi)發(fā)中的Surface庫(kù)及用其制作播放器UI的例子
這篇文章主要介紹了Android開(kāi)發(fā)中的Surface庫(kù)及用其制作播放器界面的例子,利用SurfaceView和SurfaceHolder可以高效地繪制和控制圖形界面,需要的朋友可以參考下2016-04-04
Jetpack?Compose入門(mén)基礎(chǔ)全面精講
開(kāi)始布局部分。這部分我個(gè)人感覺(jué)沒(méi)有必要每個(gè)組件、屬性都詳細(xì)說(shuō)到,否則篇幅會(huì)很長(zhǎng)。建立起Compose中的組件與?Android?Views的一個(gè)對(duì)應(yīng)關(guān)系就夠了。具體還是需要在實(shí)際的使用中去熟悉2022-10-10
Android實(shí)現(xiàn)下載zip壓縮文件并解壓的方法(附源碼)
這篇文章主要給大家介紹了利用Android實(shí)現(xiàn)下載zip壓縮文件并解壓的方法,文中給出了示例代碼并提供了源碼下載,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-02-02
Android編程實(shí)現(xiàn)仿易信精美彈出框效果【附demo源碼下載】
這篇文章主要介紹了Android編程實(shí)現(xiàn)仿易信精美彈出框效果,涉及Android窗口及動(dòng)畫(huà)操作相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-01-01
關(guān)于Android Fragment對(duì)回退棧的詳細(xì)理解
這篇文章主要介紹了Android Fragment的回退棧示例詳細(xì)介紹的相關(guān)資料,在Android中Fragment回退棧是由Activity管理的,每個(gè)Activity都有自己的回退棧,其中保存了已經(jīng)停止(處于后臺(tái))的Fragment實(shí)例,需要的朋友可以參考下2016-12-12

