【记录】Tom猫——用Animation-list逐帧动画实现

第一步:准备图片素材,放到res/drawable目录下

图片素材下载地址:https://pan.baidu.com/s/1kZOHw0YY-xuvP0Ip-zXhdw(若链接失效请联系作者索取)密码:czh0
Tom

第二步:创建动画文件,放到res/drawable目录下

<?xml version="1.0" encoding="utf-8"?>

<!--   
    根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画  
    根标签下,通过item标签对动画中的每一个图片进行声明  
    android:duration 表示展示所用的该图片的时间长度  
 --> 

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
    <item android:drawable="@drawable/background" android:duration="100"></item>
    <item android:drawable="@drawable/poke_belly_right_0001" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0002" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0003" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0004" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0005" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0006" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0007" android:duration="100"/>
    <item android:drawable="@drawable/poke_belly_right_0008" android:duration="100"/>
    <item android:drawable="@drawable/background" android:duration="100"></item>
</animation-list>

第三步:在布局文件,mian.xml 中引入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" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/ani" />

</RelativeLayout>

第四步:在MianActivity中播放动画

public class MainActivity extends Activity
{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView imageView = (ImageView) findViewById(R.id.imageView1);
        final AnimationDrawable background = (AnimationDrawable) imageView.getBackground();
        imageView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)
            {
                // 停止上一次的动画,然后开始播放
                background.stop();
                background.start();
            }
        });
    }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值