Android图形与图像处理-逐帧动画

Android图形与图像处理-逐帧动画

实例:功夫熊猫

创建项目:FatPo

项目运行效果:

 

   

项目截图:

 

布局文件:main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:background="#fff"
	>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="horizontal"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:gravity="center"
	>
<Button 
	android:id="@+id/play"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/play"/>
<Button 
	android:id="@+id/stop"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/stop"/>	
</LinearLayout>
<ImageView  
	android:id="@+id/anim"
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content" 
	android:background="@anim/fat_po"
	android:scaleType="center"
	/>
</LinearLayout>


动画资源资源文件:res\anim\fat_po.xml

要事先导入相应的图片资源


<?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/fat_po_f01" android:duration="60"/>
    <item android:drawable="@drawable/fat_po_f02" android:duration="60"/>
    <item android:drawable="@drawable/fat_po_f03" android:duration="60"/>
    <item android:drawable="@drawable/fat_po_f04" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f05" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f06" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f07" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f08" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f09" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f10" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f11" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f12" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f13" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f14" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f15" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f16" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f17" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f18" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f19" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f20" android:duration="60" />
	<item android:drawable="@drawable/fat_po_f21" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f22" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f23" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f24" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f25" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f26" android:duration="60" />	
	<item android:drawable="@drawable/fat_po_f27" android:duration="60" />	
</animation-list>

 

Activity文件:FatPo.java

package wwj.fatpo;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class FatPo extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //获取两个按钮
        Button play = (Button) findViewById(R.id.play);
        Button stop = (Button) findViewById(R.id.stop);
        ImageView imageView = (ImageView)findViewById(R.id.anim);
        //获取AnimationDrawable动画对象
        final AnimationDrawable anim = (AnimationDrawable)imageView.getBackground();
        play.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//开始播放动画
				anim.start();
			}
		});
        stop.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//停止播放动画
				anim.stop();
			}
		});
    }
}


 


 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小巫技术博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值