Android利用animation-list實(shí)現(xiàn)幀動(dòng)畫
本文實(shí)例為大家分享了利用animation-list實(shí)現(xiàn)幀動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下
將要順序播放的圖片放在資源目錄下
再drawable目錄下新建animation1文件和animation2文件 一個(gè)是按順序顯示動(dòng)畫,一個(gè)是倒序顯示動(dòng)畫,
順序顯示動(dòng)畫文件:animation1.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會(huì)不停的循環(huán)播放動(dòng)畫 根標(biāo)簽下,通過item標(biāo)簽對(duì)動(dòng)畫中的每一個(gè)圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時(shí)間長(zhǎng)度 --> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/icon1" android:duration="150"></item> <item android:drawable="@drawable/icon2" android:duration="150"></item> <item android:drawable="@drawable/icon3" android:duration="150"></item> <item android:drawable="@drawable/icon4" android:duration="150"></item> <item android:drawable="@drawable/icon5" android:duration="150"></item> <item android:drawable="@drawable/icon6" android:duration="150"></item> </animation-list>
倒序顯示動(dòng)畫文件:animation2.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 根標(biāo)簽為animation-list,其中oneshot代表著是否只展示一遍,設(shè)置為false會(huì)不停的循環(huán)播放動(dòng)畫 根標(biāo)簽下,通過item標(biāo)簽對(duì)動(dòng)畫中的每一個(gè)圖片進(jìn)行聲明 android:duration 表示展示所用的該圖片的時(shí)間長(zhǎng)度 --> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/icon6" android:duration="150"></item> <item android:drawable="@drawable/icon5" android:duration="150"></item> <item android:drawable="@drawable/icon4" android:duration="150"></item> <item android:drawable="@drawable/icon3" android:duration="150"></item> <item android:drawable="@drawable/icon2" android:duration="150"></item> <item android:drawable="@drawable/icon1" android:duration="150"></item> </animation-list>
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/animationIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:src="@drawable/animation1"/>
<Button android:id="@+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="順序顯示" />
<Button android:id="@+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="停止" />
<Button android:id="@+id/buttonC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="倒序顯示" />
</LinearLayout>
Activity文件
package org.shuxiang.test;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
public class Activity10 extends Activity
{
private ImageView animationIV;
private Button buttonA, buttonB, buttonC;
private AnimationDrawable animationDrawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test10);
animationIV = (ImageView) findViewById(R.id.animationIV);
buttonA = (Button) findViewById(R.id.buttonA);
buttonB = (Button) findViewById(R.id.buttonB);
buttonC = (Button) findViewById(R.id.buttonC);
buttonA.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation1);
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
buttonB.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.stop();
}
});
buttonC.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation2);
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android結(jié)合xml實(shí)現(xiàn)幀動(dòng)畫
- Android動(dòng)畫系列之幀動(dòng)畫和補(bǔ)間動(dòng)畫的示例代碼
- Android 幀動(dòng)畫的實(shí)例詳解
- Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解
- Android之仿美團(tuán)加載數(shù)據(jù)幀動(dòng)畫
- Android逐幀動(dòng)畫實(shí)現(xiàn)代碼
- android 幀動(dòng)畫,補(bǔ)間動(dòng)畫,屬性動(dòng)畫的簡(jiǎn)單總結(jié)
- Android 使用幀動(dòng)畫內(nèi)存溢出解決方案
- Android幀動(dòng)畫、補(bǔ)間動(dòng)畫、屬性動(dòng)畫用法詳解
- Android 幀動(dòng)畫使用詳情
相關(guān)文章
android實(shí)現(xiàn)多點(diǎn)觸摸應(yīng)用
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)多點(diǎn)觸摸應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android Surfaceview的繪制與應(yīng)用
這篇文章主要介紹了Android Surfaceview的繪制與應(yīng)用的相關(guān)資料,需要的朋友可以參考下2017-07-07
Android 實(shí)現(xiàn)微信長(zhǎng)按菜單 -FloatMenu
在日常開發(fā)中,長(zhǎng)按某個(gè)view出現(xiàn)個(gè)菜單是很常見的需求,下面小編給大家?guī)砹薃ndroid 實(shí)現(xiàn)微信長(zhǎng)按菜單 -FloatMenu的實(shí)現(xiàn)思路及具體實(shí)現(xiàn)代碼,感興趣的朋友跟隨腳本之家小編一起看看吧2018-07-07
詳解如何實(shí)現(xiàn)一個(gè)Kotlin函數(shù)類型
這篇文章主要為大家詳細(xì)介紹了如何實(shí)現(xiàn)一個(gè)Kotlin函數(shù)類型,文中的實(shí)現(xiàn)方法講解詳細(xì),具有一定的借鑒價(jià)值,需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-10-10
Android應(yīng)用隱私合規(guī)檢測(cè)實(shí)現(xiàn)方案詳解
這篇文章主要介紹了Android應(yīng)用隱私合規(guī)檢測(cè)實(shí)現(xiàn)方案,我們需要做的就是提前檢測(cè)好自己的應(yīng)用是否存在隱私合規(guī)問題,及時(shí)整改過來,下面提供Xposed Hook思路去檢測(cè)隱私合規(guī)問題,建議有Xposed基礎(chǔ)的童鞋閱讀,需要的朋友可以參考下2022-07-07
Android二級(jí)緩存加載圖片實(shí)現(xiàn)照片墻功能
這篇文章主要為大家詳細(xì)介紹了Android二級(jí)緩存加載圖片實(shí)現(xiàn)照片墻功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android?實(shí)現(xiàn)卡片堆疊錢包管理動(dòng)畫效果
這篇文章主要介紹了Android?實(shí)現(xiàn)卡片堆疊錢包管理動(dòng)畫效果,實(shí)現(xiàn)思路是在動(dòng)畫回調(diào)中requestLayout?實(shí)現(xiàn)動(dòng)畫效果,用Bounds?對(duì)象記錄每一個(gè)CardView?對(duì)象的初始位置,當(dāng)前位置,運(yùn)動(dòng)目標(biāo)位置,需要的朋友可以參考下2022-07-07
Android EditText實(shí)現(xiàn)關(guān)鍵詞批量搜索示例
本篇文章主要介紹了Android EditText實(shí)現(xiàn)關(guān)鍵詞批量搜索示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02

