zoukankan      html  css  js  c++  java
  • (原)android中的动画(二)

    帧动画的使用需要在xml文件中指定每一帧所对应的图片

    animation-list写法如下:

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item
            android:drawable="@drawable/b1"
            android:duration="200"/>
        <item
            android:drawable="@drawable/b2"
            android:duration="200"/>
        <item
            android:drawable="@drawable/b3"
            android:duration="200"/>
        <item
            android:drawable="@drawable/b4"
            android:duration="200"/>
        <item
            android:drawable="@drawable/b5"
            android:duration="200"/>
        <item
            android:drawable="@drawable/b6"
            android:duration="200"/>
    
    </animation-list>

    播放帧动画的java代码如下:

    iv.setImageResource(R.drawable.myanimationlist);
            AnimationDrawable animation = (AnimationDrawable) iv.getDrawable();
            animation.start(); // 开始播放动画

    旋转,平移,缩放,渐变这四种补间动画的写法很相似,统一列在下面:

    public void rote(View v) {
            RotateAnimation rotateAnimation = new RotateAnimation(0, 180,
                    iv.getWidth() / 2, iv.getHeight() / 2);
            rotateAnimation.setDuration(2000);
            iv.startAnimation(rotateAnimation);
        }
    
        public void translate(View v) {
            TranslateAnimation translateAnimation = new TranslateAnimation(0, 200,
                    0, 200);
            translateAnimation.setDuration(2000);
            iv.startAnimation(translateAnimation);
        }
    
        public void scale(View v) {
            ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 2, 0.5f, 2,
                    iv.getWidth() / 2, iv.getHeight() / 2);
            scaleAnimation.setDuration(2000);
            iv.startAnimation(scaleAnimation);
    
        }
    
        public void alpha(View v) {
            AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
            alphaAnimation.setDuration(2000);
            iv.startAnimation(alphaAnimation);
        }

    补间动画同时只能有一个在执行,如果想让几种补间动画同时执行的话,可以使用animationSet:

    public void together(View v) {
            AnimationSet animationSet = new AnimationSet(false);
            RotateAnimation rotateAnimation = new RotateAnimation(0, 180,
                    iv.getWidth() / 2, iv.getHeight() / 2);
            rotateAnimation.setDuration(2000);
            TranslateAnimation translateAnimation = new TranslateAnimation(0, 200,
                    0, 200);
            translateAnimation.setDuration(2000);
            ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 2, 0.5f, 2,
                    iv.getWidth() / 2, iv.getHeight() / 2);
            scaleAnimation.setDuration(2000);
            AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
            alphaAnimation.setDuration(2000);
            animationSet.addAnimation(rotateAnimation);
            animationSet.addAnimation(translateAnimation);
            animationSet.addAnimation(scaleAnimation);
            animationSet.addAnimation(alphaAnimation);
            iv.startAnimation(animationSet);
        }

    这样几种补间动画就可以一起执行了

    这篇先总结到这里,下篇总结动画监听事件以及页面切换动画.

  • 相关阅读:
    监控服务器配置(一)-----Prometheus安装配置
    mongo可视化工具adminMongo安装
    Grafana 下载与安装(v5.4.1)
    Grafana+Prometheus系统监控之Redis
    聊聊redis的监控工具
    Linux 服务器buff/cache清理
    redis为什么内存不宜过大
    Python 操作 mongodb 亿级数据量使用 Bloomfilter 高效率判断唯一性 例子
    Redis-3.2.0集群配置(redis cluster)
    在reshard过程中,将会询问reshard多少slots:
  • 原文地址:https://www.cnblogs.com/BlogCommunicator/p/4916840.html
Copyright © 2011-2022 走看看