• android 动画总结


    以下博文讲解比较详细,可查阅:

    http://www.360doc.com/content/13/0102/22/6541311_257754535.shtml

    几个关键属性:

          
    setRepeatCount(int repeatCount);//设置动画重复执行的次数
    setStartOffSet(long startOffSet);//设置动画执行之前的等待时间。
    setFillBefore(Boolean fillBefore);//true则动画执行完成后,回到最初的状态。
    setFillAfter(Boolean fillAfter);//true 动画保持完成状态。
    setDuration(long duration);//动画持续时间

    以下为自己封装的动画工具类,只是最简单的封装。

    package com.create.utilslibrary;
    
    import android.content.Context;
    import android.view.View;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.Animation;
    import android.view.animation.AnimationSet;
    import android.view.animation.DecelerateInterpolator;
    import android.view.animation.RotateAnimation;
    import android.view.animation.ScaleAnimation;
    import android.view.animation.TranslateAnimation;
    
    /**
     * Created by Administrator on 2016/5/19 0019.
     */
    public class AnimatorUtils {
        /**
         * 条目动画
         *
         * @param context
         * @param view
         * @param position
         */
        public static void runEnterAnimation(Context context, View view, int position) {
            view.setTranslationY(ScreenUtil.getScreenHight(context));
            view.animate()
                    .translationY(0)
                    .setStartDelay(100 * (position % 15))
                    .setInterpolator(new DecelerateInterpolator(3.f))
                    .setDuration(700)
                    .start();
        }
    
        /**
         * 渐变动画,淡入淡出 动画完成后保持在结束位置
         *
         * @param fromAlpha 开始的渐变值  0f 表开始时是全透明   1f表开始时是完全显示  值为 0--1f之间
         * @param toAlpha   结束的渐变值  0f 表结束时是全透明   1f表结束时是完全显示   值为 0--1f之间
         * @param duration  动画持续时间  毫秒
         * @return
         */
        public static AlphaAnimation getAlpaAnimation(float fromAlpha, float toAlpha, long duration) {
            AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, fromAlpha);
            alphaAnimation.setDuration(duration);
            return alphaAnimation;
        }
    
        /**
         * 平移动画  动画完成后保持在结束位置
         * 参考对象是view本身:Animation.RELATIVE_TO_SELF
         *
         * @param fromXvelue x轴方向 开始的值,相对于view宽度(x轴坐标) 的百分比  0f表示从view的最左侧的坐标点开始动画,1f表示从最右侧开始  值为 0f--1f之间
         * @param toXvelue   x轴方向 结束的值,相对于view宽度 的百分比  0f表示到view的最左侧坐标点时结束,1f表示到最右侧坐标点结束    值为 0f--1f之间
         * @param fromYValue y轴方向 开始的值,相对于view高度(y轴坐标) 的百分比  0f表示从view的最顶部的坐标点开始动画,1f表示从最底部的坐标点开始 值为 0f--1f之间
         * @param toYValue   y轴方向 结束的值,相对于view高度 的百分比  0f表示到view的最顶部的坐标点时结束,1f表示到底部的坐标点结束 值为 0f--1f之间
         * @param duration   动画持续时间
         * @return
         */
        public static TranslateAnimation getTranslateAnimation(float fromXvelue,
                                                               float toXvelue,
                                                               float fromYValue,
                                                               float toYValue,
                                                               long duration
        ) {
            TranslateAnimation translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, fromXvelue, Animation.RELATIVE_TO_SELF, toXvelue,
                    Animation.RELATIVE_TO_SELF, fromYValue, Animation.RELATIVE_TO_SELF, toYValue
            );
            translateAnimation.setDuration(duration);
            return translateAnimation;
        }
    
        /**
         * 缩放动画  动画完成后保持在结束位置
         * @param fromX 开始的x轴大小  相对于自身宽度的比例    0f--1f之间
         * @param toX    结束的x轴的大小  相对于自身宽度的比例 0f--1f之间
         * @param fromY  开始的y轴大小  相对于自身高度的比例    0f--1f之间
         * @param toY    结束的y轴大小  相对于自身高度的比例    0f--1f之间
         *
         * 以下四个值是确定缩放开始的坐标点。
         * @param pivotXType  Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
         * @param pivotXValue  0f--1f之间的值
         * @param pivotYType  同上
         * @param pivotYValue  同上
         * @return
         */
        public static ScaleAnimation getScaleAnimation(float fromX,
                                                       float toX,
                                                       float fromY,
                                                       float toY,
                                                       int pivotXType,
                                                       float pivotXValue,
                                                       int pivotYType,
                                                       float pivotYValue,
                                                       long duration
                                                      ){
            ScaleAnimation scaleAnimation = new ScaleAnimation(fromX, toX, fromY, toY,
                    pivotXType, pivotXValue, pivotYType, pivotYValue);
            scaleAnimation.setDuration(duration);
            scaleAnimation.setFillAfter(true);
            return scaleAnimation;
        }
    
        /**
         * 旋转动画  保持在结束位置
         * @param fromDegrees 开始角度
         * @param toDegrees   结束角度
         * 以下四个参数用户旋转的圆心
         * @param pivotXType  确定x轴坐标参照类型 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
         * @param pivotXValue  x轴 的坐标值  0f--1f
         * @param pivotYType   确定y轴的坐标参照类型   Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
         * @param pivotYValue  y轴 的坐标值  0f--1f
         * @return
         */
        public static RotateAnimation getRotateAnimation(float fromDegrees,
                                                         float toDegrees,
                                                         int pivotXType,
                                                         float pivotXValue,
                                                         int pivotYType,
                                                         float pivotYValue,
                                                         long duration
                                                         ){
          RotateAnimation rotateAnimation=new RotateAnimation(fromDegrees,toDegrees,
                      pivotXType,pivotXValue,pivotYType,pivotYValue);
            rotateAnimation.setDuration(duration);
            rotateAnimation.setFillAfter(true);
            return rotateAnimation;
        }
        /**
         * 创建动画集合对象
         * @param bool  true 所有集合中的动画使用 集合的插值器, false表各个动画使用自己的插值器。
         * @return
         */
        public  static AnimationSet getAnimationSet(Boolean bool) {
            AnimationSet animationSet = new AnimationSet(false);
              return animationSet;
        }
    }
  • 相关阅读:
    [C++]仿java.lang.String的字符串工具类[原]
    SQL基础1创建表、用户
    Linux中gdb 查看core堆栈信息
    Direct3D9基础工具类[原]
    eclipse3.4启动错误
    ndk连接第三方库
    数据库基本概念
    MySQL常见命令
    MySQL启动和停止
    MySQL配置文件
  • 原文地址:https://www.cnblogs.com/epmouse/p/5674305.html
Copyright © 2020-2023  润新知