• Android自定义窗口动画


    第一步,设置出现和消失的xml

    1、在res/anim下创建enter_anim.xml,设置窗口出现的动画

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 弹出时动画 -->
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale 
            android:interpolator="@android:anim/accelerate_interpolator"
            android:fromXScale="1.0"
            android:toXScale="1.0"
            android:fromYScale="0.0"
            android:toYScale="1.0"
            android:pivotX="0%"
            android:pivotY="100%"
            android:fillAfter="false"
            android:duration="500"/>
    </set>
    <!--
    android:fromXscale="1.0" 表示开始时X轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
    android:toXscale="0.0"表示结束时X轴缩放比例为0.0(原图大小 *0.0 为缩小到看不见)
    android:fromYscale="1.0" 表示开始时Y轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
    android:toYscale="0.0"表示结束时Y轴缩放比例为0.0(原图大小 *0.0 为缩小的看不到了)
    android:pivotX="50%" X轴缩放的位置为中心点
    android:pivotY="50%" Y轴缩放的位置为中心点
    android:duration="2000" 动画播放时间 这里是2000毫秒也就是2秒

    -->

    2、在res/anim下创建exit_anim.xml,设置窗口消失的动画

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 退出时动画效果 -->
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale 
            android:interpolator="@android:anim/accelerate_interpolator"
            android:fromXScale="1.0"
            android:toXScale="1.0"
            android:fromYScale="1.0"
            android:toYScale="0.0"
            android:pivotX="0%"
            android:pivotY="100%"
            android:fillAfter="false"
            android:duration="500"/>
    </set>
    <!--     
    android:fromXscale="1.0" 表示开始时X轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
    android:toXscale="0.0"表示结束时X轴缩放比例为0.0(原图大小 *0.0 为缩小到看不见)
    android:fromYscale="1.0" 表示开始时Y轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
    android:toYscale="0.0"表示结束时Y轴缩放比例为0.0(原图大小 *0.0 为缩小的看不到了)
    android:pivotX="50%" X轴缩放的位置为中心点 android:pivotY="50%" Y轴缩放的位置为中心点
    android:duration="2000" 动画播放时间 这里是2000毫秒也就是2秒
    -->

    第二步,在res/values下创建动画style

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 设置出现,消失动画 -->
    <resources>
        <style name="WindowAnim" parent="android:Animation" mce_bogus="1">
            <item name="android:windowEnterAnimation">@anim/enter_anim</item>
            <item name="android:windowExitAnimation">@anim/exit_anim</item>
        </style>
    </resources>


    第三步,在代码中设置动态展现

    window.setWindowAnimations(R.style.WindowAnim); //设置窗口弹出动画  


    最后就可以演示你自己的动画效果了。

     

  • 相关阅读:
    test
    Data mining with WEKA, Part 2: Classification and clustering
    MyISAM和InnoDB的区别
    SpringMVC源码剖析(一) 从抽象和接口说起
    数据库隔离级别详解
    spring MVC配置详解
    Spring单实例、多线程安全、事务解析
    mysql中int、bigint、smallint 和 tinyint的区别
    SpringMVC源码剖析(二) DispatcherServlet的前世今生
    SpringBoot与Lombok
  • 原文地址:https://www.cnblogs.com/wytings/p/4116212.html
Copyright © 2020-2023  润新知