Dialog從頂部彈出,底部退出

第一步:定義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動起來了~~~

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容