博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android中帧动画在Activity启动时自动运行的几种方式
阅读量:4058 次
发布时间:2019-05-25

本文共 1662 字,大约阅读时间需要 5 分钟。

Android中帧动画在Activity启动时自动运行的几种方式

帧动画:

第一种方式启动帧动画:(在Activity启动时会自动运行动画)

AnimationDrawable ad

ImageView iv = (ImageView) findViewById(R.id.animation_view);

iv.setBackgroundResource(R.drawable.animation);

ad = (AnimationDrawable) iv.getBackground();

iv.getViewTreeObserver().addOnPreDrawListener(opdl);

//当一个视图树将要绘制时产生事件,可以添加一个其事件处理函数

 

OnPreDrawListener opdl=new OnPreDrawListener(){

      @Override

      public boolean onPreDraw() {

         ad.start();

         return true; //注意此行返回的值

      }

   };

第二种方式启动动画:(在Activity启动时会自动运行动画)

ImageView image = (ImageView) findViewById(R.id.animation_view);

image.setBackgroundResource(R.anim.oldsheep_wait);

        animationDrawable = (AnimationDrawable) image.getBackground();

        RunAnim runAnim=new RunAnim();

        runAnim.execute("");

 

class RunAnim extends AsyncTask<String, String, String>

{

        @Override

        protected String doInBackground(String... params)

        {

            if (!animationDrawable.isRunning())

            {

                animationDrawable.stop();

                animationDrawable.start();

            }

            return "";

        }

}

 

第三种方式启动动画:(在Activity启动时会自动运行动画)

ImageView image = (ImageView) findViewById(R.id.animation_view);

image.setBackgroundResource(R.anim.oldsheep_wait);

        animationDrawable = (AnimationDrawable) image.getBackground();

image.post(new Runnable()

 {

            @Override

            public void run()

            {

                animationDrawable.start();

            }

        });

 

第四种方式启动动画:(在Activity启动时会自动运行动画)

ImageView image = (ImageView) findViewById(R.id.animation_view);

image.setBackgroundResource(R.anim.oldsheep_wait);

        animationDrawable = (AnimationDrawable) image.getBackground();

 

@Override

    public void onWindowFocusChanged(boolean hasFocus)

    {

        animationDrawable.start();

        super.onWindowFocusChanged(hasFocus);

    }

这个ad.start不能直接写在onClickonStartonResume里面,是无效的,无法启动动画,只能写在比如事件监听当中

转载地址:http://epqci.baihongyu.com/

你可能感兴趣的文章
Django框架全面讲解 -- Form
查看>>
今日互联网关注(写在清明节后):每天都有值得关注的大变化
查看>>
”舍得“大法:把自己的优点当缺点倒出去
查看>>
[今日关注]鼓吹“互联网泡沫,到底为了什么”
查看>>
[互联网学习]如何提高网站的GooglePR值
查看>>
[关注大学生]求职不可不知——怎样的大学生不受欢迎
查看>>
[关注大学生]读“贫困大学生的自白”
查看>>
[互联网关注]李开复教大学生回答如何学好编程
查看>>
[关注大学生]李开复给中国计算机系大学生的7点建议
查看>>
[茶余饭后]10大毕业生必听得歌曲
查看>>
VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
查看>>
VUE-Vue.js之$refs,父组件访问、修改子组件中 的数据
查看>>
Python自动化之pytest常用插件
查看>>
Python自动化之pytest框架使用详解
查看>>
【正则表达式】以个人的理解帮助大家认识正则表达式
查看>>
性能调优之iostat命令详解
查看>>
性能调优之iftop命令详解
查看>>
非关系型数据库(nosql)介绍
查看>>
移动端自动化测试-Windows-Android-Appium环境搭建
查看>>
Xpath使用方法
查看>>