天天看點

PopupWindow的顯示隐藏配置動畫

如果對PopupWindow的顯示隐藏過程配置動畫。

有幾個注意點:

1.PopupWindow的動畫需要成對配置,即一個顯示一個隐藏。

2.調用PopupWindow setAnimationStyle接口來設定。

定義一個Style

<style name="popup_animation">
        <item name="@android:windowEnterAnimation">@anim/xiaoying_popup_show</item>
        <item name="@android:windowExitAnimation">@anim/xiaoying_popup_hide</item>
    </style>
           

 提供兩個例子動畫

顯示動畫:

<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <scale
        android:duration="500"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/bounce_interpolator"
        android:pivotX="50%p"
        android:pivotY="50%p"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>
           

隐藏動畫:

<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%p"
        android:pivotY="50%p"
        android:toXScale="0.0"
        android:toYScale="0.0" />

</set>
           

調用:

mPopupWindow.setAnimationStyle(R.style.popup_animation);
           

最後在動畫配置過程中發現還有問題,沒解決,有經驗的同學請指教。

問題:

對于不占滿整個window的畫面的情況,動畫不能從有效的View的相對0點開始做動畫。比如有效的view的bottom值為400px,

demo中的動畫,看到的效果是從螢幕的最下方開始做動畫的。