zoukankan      html  css  js  c++  java
  • 利用XMl标签定义动画

    渐变透明度动画

    <?xml version="1.0" encoding="utf-8"?>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
           android:fromAlpha="1.0"
           android:toAlpha="0.1"
           android:duration="3000"
           android:fillBefore="true">
    </alpha>

    旋转动画

    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
            android:fromDegrees="0"
            android:toDegrees="-650"
            android:duration="3000"
            android:fillAfter="true">
    </rotate>

    缩放动画

    <?xml version="1.0" encoding="utf-8"?>
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
           android:fromXScale="1.0"//动画起始时,控件在X轴方向上相对自身的缩放比例,1.0代表自身没有变化,0.5代表缩小一倍,2.0代表放大一倍
           android:toXScale="0.4" //动画结束时,控件在X轴方向上相对自身的缩放比例,数值代表含义同上
           android:fromYScale="1.2"//动画起始时,控件在Y轴方向上相对自身的缩放比例,1.0代表自身没有变化,0.5代表缩小一倍,2.0代表放大一倍
           android:toYScale="0.6"//动画结束时,控件在Y轴方向上相对自身的缩放比例,1.0代表自身没有变化,0.5代表缩小一倍,2.0代表放大一倍
           android:pivotX="50%"  //缩放起始点X轴的坐标,可以是数值,百分数,百分数p,表示在当前视图的左上角,数值即原点处加上数值作为缩放起始点的X轴坐标,50%则表示当前控件的左上角加上自己的宽度的50%作为缩放起始点X轴坐标,如果是50%P则是父控件宽度的50%
           android:pivotY="50%"//缩放起始点Y轴的坐标,含义同上
           android:duration="700"//动画持续时间
           android:fillBefore="true"//动画结束时,还原到初始化状态
           android:repeatCount="1"//动画重复次数
           android:repeatMode="reverse"//重复模式,reverse倒序回放,restart 代表重放
            />

    平移动画

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
               android:fromXDelta="0"
               android:toXDelta="-80"
               android:fromYDelta="0"
               android:toYDelta="-80"
               android:duration="2000">
    </translate>

    动画集

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:duration="3000"
         android:fillAfter="true">
        <alpha
                android:fromAlpha="0.0"
                android:toAlpha="1.0"/>
    
        <scale
                android:fromXScale="0.0"
                android:toXScale="1.4"
                android:fromYScale="0.0"
                android:toYScale="1.4"
                android:pivotX="50%"//缩放中心点X轴的坐标
                android:pivotY="50%"/>//缩放中心点X轴的坐标
    
        <rotate
                android:fromDegrees="0"
                android:toDegrees="720"
                android:pivotX="50%" //旋转中心点X轴的坐标
                android:pivotY="50%"/>////旋转中心点Y轴的坐标
    
    </set>

    代码中使用:

             TextView tv = (TextView)findViewById(R.id.tv);
                    /**
                     * 缩放动画
                     */
                    Animation scaleAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scaleanim);
                    /**
                     * 透明度动画
                     */
                    Animation alphaAnim = AnimationUtils.loadAnimation(MainActivity.this,R.anim.alphaanim);
                    /**
                     * 旋转动画
                     */
                    Animation rotateAnim = AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotateanim);
                    /**
                     * 平移动画
                     */
                    Animation tanslateAnim = AnimationUtils.loadAnimation(MainActivity.this,R.anim.translateanim);
                    /**
                     * 动画集合
                     */
                    Animation setAnim = AnimationUtils.loadAnimation(MainActivity.this,R.anim.setanim);
                    tv.startAnimation(setAnim);
  • 相关阅读:
    for循环删除数组中的元素crash问题
    iOS判断字符串中含不含有汉字
    iOS 拨打电话(解决openURL延迟和不同方法比较)
    ios oc单例宏定义
    iOS UIBezierPath简单实用
    iOS视图切割圆角
    iOS 内购集成与遇到的坑,添加新内购项目
    iOS工程中创建pch文件
    四舍五入的方法
    ScrollView定时器复用
  • 原文地址:https://www.cnblogs.com/loaderman/p/10194766.html
Copyright © 2011-2022 走看看