如何在安卓中实现从底部到顶部的弹出窗口动画

5
如何在Android上将弹出窗口从底部向上动画,并将窗口放置在用户单击的位置,有人可以提供代码吗?
谢谢。
2个回答

9

values\style.xml:

<resources>
<style name="AnimationPopup">
    <item name="@android:windowEnterAnimation">@anim/appear</item>
    <item name="@android:windowExitAnimation">@anim/disappear</item>
</style>
</resources>

anim\appear.xml

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

<scale
    android:duration="1000"
    android:fillAfter="false"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="90%"
    android:toXScale="1.0"
    android:toYScale="1.0" />
</set>

anim\disappear.xml

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

<scale
    android:duration="1000"
    android:fillAfter="false"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="90%"
    android:toXScale="0.0"
    android:toYScale="0.0" />
</set>

我使用 popWindow.setAnimationStyle(R.style.AnimationPopup); 设置动画,但是没有任何效果。 - Venus

4
请使用这些xml文件将翻译从底部到顶部或反之亦然。 anim\pull_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="100%"
        android:toYDelta="0%" />
</set>

anim\pull_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0%"
        android:toYDelta="100%" />
</set>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接