6

我有兴趣在我的 android 应用程序中添加一个关于切换 TextView 可见性的动画。我希望它不只是将 Visibility 设置为 Visibility.GONE 和 Visibility.VISIBLE - 相反,我希望它具有类似 jquery 的幻灯片效果。这很容易实现吗?

4

1 回答 1

14

应该不难,把动画写在xml里,放在res/anim下。我不熟悉您所追求的确切动画,但幻灯片看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:repeatCount="0" >

    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="-100%"
        android:toYDelta="0%" />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>

你在视图上设置它是这样的:

Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
view.startAnimation(anim);

如果您确保在 xml 中设置了“fillAfter”属性,则无需担心设置可见性(当然,只要您的动画更改 alpha)。

要滑出,只需制作另一个相反的动画。

于 2013-05-31T00:10:01.157 回答