Dialog从顶部弹出,底部退出

2016-11-29  本文已影响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动起来了~~~

上一篇 下一篇

猜你喜欢

热点阅读