首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android开发之帧动画

Android开发之帧动画

作者头像
YungFan
发布2018-04-24 15:05:33
6590
发布2018-04-24 15:05:33
举报
文章被收录于专栏:学海无涯学海无涯学海无涯
Android动画主要分为3种
  • View动画(Android开发之View动画)
  • 帧动画
  • 属性动画
何为帧动画?

帧动画最简单,通过顺序播放一系列的图像产生动画,有点类似动画片

以tomcat案例来讲解

1、首先准备好一组图片(网上找的现成的一组图片),然后定义一个AnimationDrawable,命名为ani.xml,按照图片顺序排好,如下:
<?xml version="1.0" encoding="utf-8"?>
<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>
2、将上述的Drawable作为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:background="@drawable/ani" />

</RelativeLayout>
3、通过AnimationDrawable 来播放动画,这里设置点击背景时触发动画,代码很简单,就没有加注释了
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()
        {

            public void onClick(View v)
            {
                background.start();
            }
        });
    }

}
4、运行测试

帧动画.gif

5、注意点

帧动画虽然比较简单,但由于都是图片连续播放形成的,在图片比较多且较大的时候,容易引起OOM,所以需要谨慎选择。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016.04.13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Android动画主要分为3种
  • 何为帧动画?
  • 1、首先准备好一组图片(网上找的现成的一组图片),然后定义一个AnimationDrawable,命名为ani.xml,按照图片顺序排好,如下:
  • 2、将上述的Drawable作为ImageView的背景
  • 3、通过AnimationDrawable 来播放动画,这里设置点击背景时触发动画,代码很简单,就没有加注释了
  • 4、运行测试
  • 5、注意点
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档