将对象设置为屏幕外的动画并将其保留在屏幕上

时间:2014-08-21 18:51:21

标签: android android-animation

如何将对象移出屏幕?

这就是我将TextView从屏幕下方移动到屏幕中的方式。

slide_up_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%" android:toYDelta="0%" android:duration="500" android:fillAfter="true"/>
</set>

这是我将其移出屏幕的方式:

slide_down_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="0%" android:toYDelta="100%" android:duration="500" android:fillAfter="true"/>
</set>

但TextView再次出现。为什么呢?

1 个答案:

答案 0 :(得分:1)

这是因为它在动画之后再次呈现它,并且实际上将TextView从屏幕/布局放置到其默认位置。

<强>溶液

您需要添加一个侦听器,并将TextView的可见性设置为在侦听器末尾消失或不可见。

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) { }

            @Override
            public void onAnimationEnd(Animation animation) {
               You_text_view.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) { }
        });
相关问题