美文网首页
Dialog从顶部弹出,底部退出

Dialog从顶部弹出,底部退出

作者: 淡定丶说的是 | 来源:发表于2016-11-29 17:06 被阅读306次

第一步:定义anim文件

dialog_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <!--%p指相对于父容器-->
    <translate
        android:duration="300"
        android:fromYDelta="-100%p">
    </translate>

</set>

dialog_exit.xml

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

第二步:定义style

<style name="enter_exit_animate" parent="@style/customDialog">
      <item name="@android:windowEnterAnimation">@anim/dialog_enter</item>  //进入时的动画
      <item name="@android:windowExitAnimation">@anim/dialog_exit</item>    //退出时的动画
</style>

第三步:获取Window对象

Window window = getWindow();
window.setWindowAnimations(R.style.enter_exit_animate);  //添加动画

好了,Dialog动起来了~~~

相关文章

网友评论

      本文标题:Dialog从顶部弹出,底部退出

      本文链接:https://www.haomeiwen.com/subject/jmxzpttx.html