Dialog弹出动画

news/2024/5/17 19:46:03 标签: gitee

1.从上往下弹出: (包含了2种实现方式一种是基于放大效果的,一种是基于平移方式的,可以自己放开注释看效果;需要在res下新建anim文件夹用于存放动画文件)

<style name="AnimTop" parent="@android:style/Animation">
    <!--进入动画-->
    <item name="android:windowEnterAnimation">@anim/dialog_top_in</item>
    <!--退出动画-->
    <item name="android:windowExitAnimation">@anim/dialog_top_out</item>
</style>

进入动画:dialog_top_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fillAfter="true">
    <!-- 自上向下滑入 -->
<!--    pivotY 原点y坐标加上自身高度的百分之百 的位置-->
<!-- 放大动画实现-->
    <scale
        android:fromXScale="1"
        android:toXScale="1"
        android:fromYScale="0"
        android:toYScale="1"
        android:pivotX="0"
        android:pivotY="0"/>
<!--平移动画实现-->
<!--    <translate-->
<!--        android:fromXDelta="1"-->
<!--        android:fromYDelta="-100%p"-->
<!--        android:toXDelta="1"-->
<!--        android:toYDelta="0" />-->

</set>

退出动画:dialog_top_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fillAfter="false">
    <!-- 自下向上滑出 -->
<!-- 放大动画-->
        <scale
            android:fromXScale="1"
            android:toXScale="1"
            android:fromYScale="1"
            android:toYScale="0"
            android:pivotX="0"
            android:pivotY="0" />
<!--平移动画-->
<!--    <translate-->
<!--        android:fromXDelta="1"-->
<!--        android:fromYDelta="0"-->
<!--        android:toXDelta="1"-->
<!--        android:toYDelta="-100%p" />-->

</set>

2.从下往上弹出:

 <style name="AnimBottom" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/dialog_bottom_in</item>
        <item name="android:windowExitAnimation">@anim/dialog_bottom_out</item>
    </style>

底部弹出进入动画: dialog_bottom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200">
    <!-- 自下向上滑入 -->
<!--        <translate-->
<!--            android:fromYDelta="100%p"-->
<!--            android:toYDelta="0" />-->

    <!--    fromYScale、pivotY 和Y坐标无关只是单纯的缩放-->
    <scale
        android:fromXScale="1"
        android:fromYScale="0"
        android:pivotX="0"
        android:pivotY="100%"
        android:toXScale="1"
        android:toYScale="1" />

</set>

底部弹出退出动画: dialog_bottom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200">
    <!-- 自下向上滑出 -->
<!--        <translate-->
<!--            android:fromYDelta="0"-->
<!--            android:toYDelta="100%p" />-->

    <scale
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="0"
        android:pivotY="100%"
        android:toXScale="1"
        android:toYScale="0" />
</set>

 

3.从左往右弹出:

 <style name="AnimLeft" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/dialog_left_in</item>
        <item name="android:windowExitAnimation">@anim/dialog_left_out</item>
    </style>

进入动画:dialog_left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
            android:fromXDelta="-100%p"
            android:toXDelta="0"
            android:duration="300"/>

    <!-- pivotX 可以是   -->
<!--    <scale-->
<!--        android:fromXScale="0"-->
<!--        android:fromYScale="1"-->
<!--        android:pivotX="0"-->
<!--        android:pivotY="0"-->
<!--        android:toXScale="1"-->
<!--        android:toYScale="1" />-->

</set>

退出动画:dialog_left_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300">

        <translate
            android:fromXDelta="0"
            android:toXDelta="-100%p" />

<!--    <scale-->
<!--        android:fromXScale="1"-->
<!--        android:fromYScale="1"-->
<!--        android:toXScale="0"-->
<!--        android:toYScale="1"-->
<!--        android:pivotX="0"-->
<!--        android:pivotY="0"/>-->
</set>

 

4.从右往左弹出:

  <style name="AnimRight" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/dialog_right_in</item>
        <item name="android:windowExitAnimation">@anim/dialog_right_out</item>
    </style>

进入动画:dialog_right_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
            android:fromXDelta="100%p"
            android:toXDelta="0"
            android:duration="300"/>

    <!-- pivotX 可以是数字、百分比
    50px表示原点坐标加上50即是控件的x位置
    50%表示原点坐标加上控件自身的50%
    50%p 表示原点位置加上父控件的50%  -->
<!--    <scale-->
<!--        android:fromXScale="0"-->
<!--        android:fromYScale="1"-->
<!--        android:pivotX="100%"-->
<!--        android:pivotY="0"-->
<!--        android:toXScale="1"-->
<!--        android:toYScale="1" />-->

</set>

退出动画:dialog_right_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

        <translate
            android:fromXDelta="0"
            android:toXDelta="100%p"
            android:duration="300"/>

<!--    <scale-->
<!--        android:fromXScale="1"-->
<!--        android:fromYScale="1"-->
<!--        android:toXScale="0"-->
<!--        android:toYScale="1"-->
<!--        android:pivotX="100%"-->
<!--        android:pivotY="0"/>-->
</set>

5.从中间弹出:

    <style name="AnimCenter" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/dialog_center_in</item>
        <item name="android:windowExitAnimation">@anim/dialog_center_out</item>
    </style>

进入动画:dialog_center_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200">
    <!--    若均为 0% 或 0.0 ,起始点为 View 左上角;
            均为 50% 或 0.5 ,起始点为控件中心点;
            均为100% 或 1.0 ,起始点是 View 右下角。-->
    <!--    100%p会下移一个单位-->
    <scale
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1" />
</set>

退出动画:dialog_center_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200">
    <scale
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0" />
</set>


http://www.niftyadmin.cn/n/5414547.html

相关文章

AD20中关于“Footprint Not Found”的解决方法

问题描述&#xff1a; Footprint Not Found&#xff1a;未找到封装外形 就是说没找到你的封装&#xff0c;但是明明我有封装库文件啊&#xff0c;怎么没找到封装呢&#xff1f; 解决方法&#xff1a; 1.打开封装管理器 2.把上面这一行全选成ALL使显示所有的元器件&#xff…

【机器学习】实验5,AAAI 会议论文聚类分析

本次实验以AAAI 2014会议论文数据为基础&#xff0c;要求实现或调用无监督聚类算法&#xff0c;了解聚类方法。 任务介绍 每年国际上召开的大大小小学术会议不计其数&#xff0c;发表了非常多的论文。在计算机领域的一些大型学术会议上&#xff0c;一次就可以发表涉及各个方向…

【计算机视觉】图像处理算法(线性滤波篇)

来源&#xff1a;《OpenCV3编程入门》&#xff0c;怀念毛星云大佬&#x1f56f;️ 说明&#xff1a;本系列重点关注各种图像处理算法的原理、作用和对比 线性滤波&#xff1a;方框滤波、均值滤波、高斯滤波 平滑处理 平滑处理(smoothing)也称模糊处理(bluring),是一种简单且使…

148个Chatgpt关键词汇总-有爱AI实战教程(二)

演示站点&#xff1a; https://ai.uaai.cn 技能模块 官方论坛&#xff1a; www.jingyuai.com 京娱AI 导读&#xff1a;在使用 ChatGPT 时&#xff0c;当你给的指令越精确&#xff0c;它的回答会越到位&#xff0c;举例来说&#xff0c;假如你要请它帮忙写文案&#xff0c;如…

Sublime Text for Mac/Win:跨平台编程利器,让代码编辑更高效

在当下这个数字化、信息化的时代&#xff0c;编程已经成为越来越多人的必备技能。而对于编程者来说&#xff0c;一款好的代码编辑器不仅能提升工作效率&#xff0c;还能为创作过程增添乐趣。今天&#xff0c;我要向大家推荐的&#xff0c;就是这样一款强大的跨平台代码编辑器—…

vaspkit用POSCAR生成INCAR、KPOINTS文件

网站链接&#xff1a;https://next-gen.materialsproject.org/materials 1.下载POSCAR文件 2.用vaspkit生成INCAR、KPOINTS文件 (base) [simplelocalhost ~]$ cd test/demo/ (base) [simplelocalhost demo]$ ls POSCAR (base) [simplelocalhost demo]$ vaspkit\\\/// …

详解C语言库函数:qsort()

qsort&#xff08;&#xff09;函数是以快速排序为基础并且可以将任何类型的数据以你想要的方式进行排序。 在C官网cppreference.com上可以找到以上结果&#xff0c;翻译过来就是使用qsort要包含<stdlib.h>文件。 这个函数有四个参数qsort(void * base , size_t num, s…

Chrome浏览器好用的几个扩展程序

Chrome好用的扩展程序 背景目的介绍JsonHandle例子未完待续。。。。。。 背景 偶然在往上看到Chrome有很多好用的扩展程序&#xff0c;比较好用&#xff0c;因此记录下比较实用的扩展程序。 目的 记录Chrome浏览器好用的插件。 介绍 JsonHandle下载以及无法扩展插件的解决…