Android动画之帧动画

Android动画之帧动画,第1张

概述Android动画之帧动画帧动画,顾名思义就是一帧一帧的动画,就是把图片一张一张的按顺序的展示出来。需要用到的api是AnimationDrawable。实现方法1把图片放入一个数组中,然后利用AnimationDrawable循环遍历即可。//这里把图片放入数组中publicstaticfinalint[]ids_index AndroID动画之帧动画

帧动画,顾名思义就是一帧一帧的动画,就是把图片一张一张的按顺序的展示出来。需要用到的API是AnimationDrawable。

实现方法1

把图片放入一个数组中,然后利用AnimationDrawable循环遍历即可。

//这里把图片放入数组中public static final int[] IDs_index = {R.drawable.ic_icon_index_svg_1,R.drawable.ic_icon_index_svg_2,R.drawable.ic_icon_index_svg_3,R.drawable.ic_icon_index_svg_4            ,R.drawable.ic_icon_index_svg_5,R.drawable.ic_icon_index_svg_6,R.drawable.ic_icon_index_svg_7,R.drawable.ic_icon_index_svg_8            ,R.drawable.ic_icon_index_svg_9,R.drawable.ic_icon_index_svg_10,R.drawable.ic_icon_index_svg_11,R.drawable.ic_icon_index_svg_12            ,R.drawable.ic_icon_index_svg_13,R.drawable.ic_icon_index_svg_14,R.drawable.ic_icon_index_svg_15,R.drawable.ic_icon_index_svg_16            ,R.drawable.ic_icon_index_svg_17,R.drawable.ic_icon_index_svg_18,R.drawable.ic_icon_index_svg_19};//具体帧动画的实现//创建一个AnimationDrawable        AnimationDrawable animationDrawable1 = new AnimationDrawable();        //通过for循环添加每一帧动画        for(int i = 0 ; i < IDs_index.length ; i ++){            Drawable frame = context.getResources().getDrawable(IDs_index[i]);            //设定时长            animationDrawable1.addFrame(frame,10);        }        //true代表动画只执行一次        animationDrawable1.setoneshot(true);        //将动画设置到背景上        iv_index_icon.setimageDrawable(animationDrawable1);        //开启帧动画        animationDrawable1.start();
实现方法2

在drawable下新建一个animation-List,把要动画的每一帧图片放进去,然后把这个drawable放入要显示动画的控件中,最后利用AnimationDrawable 实现动画即可。

    AnimationDrawable animationDrawable = (AnimationDrawable) iv_index_icon.getDrawable();        //开启帧动画        animationDrawable.start();
<?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/ic_icon_index_svg_1" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_2" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_3" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_4" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_5" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_6" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_7" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_8" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_9" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_10" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_11" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_12" androID:duration="10"/>    <item androID:drawable="@drawable/ic_icon_index_svg_13" androID:duration="10"/></animation-List>
总结

以上是内存溢出为你收集整理的Android动画之帧动画全部内容,希望文章能够帮你解决Android动画之帧动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1035806.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存