简体   繁体   English

Android:滑出动画

[英]Android: Slide out Animation

I have a LinearLayout which is within a RelativeLayout and aligned to the bottom of it. 我有一个LinearLayout,它位于RelativeLayout中,并与它的底部对齐。 It's height is wrap_content. 它的高度是wrap_content。 What I'm trying to do is when the user presses a button and the action that the button does is completed, I want this LinearLayout to slide out of the bottom of the screen. 我想做的是当用户按下一个按钮并且该按钮所做的动作完成时,我希望这个LinearLayout滑出屏幕底部。 So when the animation is done the LinearLayout will no longer be in the View. 因此,完成动画后,LinearLayout将不再位于视图中。

When the animation happens what I'm actually seeing is the LinearLayout kind of flashes for a second and then nothing happens. 当动画发生时,我实际上看到的是LinearLayout闪烁一秒钟,然后什么也没有发生。

Here's my XML for the Layout: 这是我的布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:id="@+id/splash_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_screen_barcastr"
android:gravity="center_horizontal"
android:orientation="vertical" >


 <LinearLayout 
     android:id="@+id/splash_loginBox"
     android:layout_alignParentBottom="true"
     android:orientation="vertical"
     android:background="@drawable/message_editor_background_shadow"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

And this is my Animation: 这是我的动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:duration="200"
    android:fromYDelta="0%"
    android:toYDelta="100%" />
<alpha
    android:duration="200"
    android:fromAlpha="1.0"
    android:toAlpha="0.0" />

Here's where I call it: 这是我称之为的地方:

Animation slideOutAnimation = AnimationUtils.loadAnimation(getActivity(), R.drawable.splash_login_slide_out);
            slideOutAnimation.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {

                }
            });
            //Now Set your animation
            loginContainer.startAnimation(slideOutAnimation);

here is the answer: 答案是:

@Override
   public void onAnimationEnd(Animation animation) {
          loginContainer.setVisibility(View.GONE);
   }

after animation ended, make the the layout invisible 动画结束后,使布局不可见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM