android animation-list 代码,Android利用animation-list实现帧动画

本文实例为大家分享了利用animation-list实现帧动画的具体代码,供大家参考,具体内容如下

将要顺序播放的图片放在资源目录下

再drawable目录下新建animation1文件和animation2文件  一个是按顺序显示动画,一个是倒序显示动画,

顺序显示动画文件:animation1.xml

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

android:oneshot="true"

>

倒序显示动画文件:animation2.xml

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

android:oneshot="true"

>

布局文件

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="5px"

android:src="@drawable/animation1"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="5px"

android:text="顺序显示" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="5px"

android:text="停止" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="5px"

android:text="倒序显示" />

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();

}

});

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值