【Android】帧动画(86/100)

在这里插入图片描述
最近几年新的动画方式增加了许多,笔者回顾复习整理一下,以后方便取用

帧动画

Android中的动画 分为三大类,逐帧动画(Frame)以及补间动画(Tween),还有Android 3.0以后引入的属性动画 (Property), 我们本篇文章说一下帧动画,逐帧(Frame)动画是最容易理解的,它要求把动画的过程的每张静态图片都搜集起来,然后由Android来控制依次显示这些静态图片,再利用人眼"视觉暂留"的原理,给用户造成"动画"的错觉。逐帧动画的动画原理和放电影的原理是一样的。

实现上有两种方式:一种是xml,一种是代码。笔者使用代码方式进行。xml方式有兴趣童鞋自己搞搞蛤!
主要代码如下:

private void showPicsAnim() {
        animationDrawable=new AnimationDrawable();
        int time=300;
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img01),time);
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img02),time);
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img03),time);
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img04),time);
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img05),time);
        animationDrawable.addFrame(getDrawable(R.mipmap.ic_img06),time);

        animationDrawable.setOneShot(false);//false:循环播放;true:播放一次就停止
        imageView.setImageDrawable(animationDrawable);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(animationDrawable.isRunning()){
                    animationDrawable.stop();
                }else{
                    animationDrawable.start();
                }
            }
        });
        animationDrawable.start();

    }

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.anim.FrameAnimActivity">

    <ImageView
        android:layout_margin="10dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:src="@mipmap/ic_img01"
        android:scaleType="fitXY"
        android:id="@+id/iv"
        android:layout_width="match_parent"
        android:layout_height="300dp"/>

</android.support.constraint.ConstraintLayout>

就到这里啦!

自研产品推荐

历时一年半多开发终于smartApi-v1.0.0版本在2023-09-15晚十点正式上线
smartApi是一款对标国外的postman的api调试开发工具,由于开发人力就作者一个所以人力有限,因此v1.0.0版本功能进行精简,大功能项有:

  • api参数填写
  • api请求响应数据展示
  • PDF形式的分享文档
  • Mock本地化解决方案
  • api列表数据本地化处理
  • 再加上UI方面的打磨

为了更好服务大家把之前的公众号和软件激活结合,如有疑问请大家反馈到公众号即可,下个版本30%以上的更新会来自公众号的反馈。
嗯!先解释不上服务端原因,API调试工具的绝大多数时候就是一个数据模型、数据处理、数据模型理解共识的问题解决工具,所以作者结合自己十多年开发使用的一些痛点来打造的,再加上服务端开发一般是面向企业的,作者目前没有精力和时间去打造企业服务。再加上没有资金投入所以服务端开发会滞后,至于什么时候会进行开发,这个要看募资情况和用户反馈综合考虑。虽然目前国内有些比较知名的api工具了,但作者使用后还是觉得和实际使用场景不符。如果有相关吐槽也可以在作者的公众号里反馈蛤!
下面是一段smartApi使用介绍:
在这里插入图片描述

下载地址:

https://pan.baidu.com/s/1iultkXqeLNG4_eNiefKTjQ?pwd=cnbl

posted @ 2022-08-05 15:40  lichong951  阅读(4)  评论(0编辑  收藏  举报  来源