2014-06-28 125 views
1

我有一个LinearLayout,它位于RelativeLayout中并与其底部对齐。它的高度是wrap_content。我想要做的是,当用户按下一个按钮并且该按钮所执行的操作已完成时,我希望此LinearLayout滑出屏幕底部。所以当动画完成后,LinearLayout将不再处于视图中。Android:滑出动画

当动画发生时,我实际上看到的是LinearLayout类型的闪烁一秒钟,然后什么也没有发生。

这里是我的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"> 

这是我的动画:

<?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" /> 

此处,我把它叫做:

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); 
+1

你为什么不设置这个happend的LinearLayout中的知名度飘否则某物:onAnimationEnd()? –

+1

因为我没有想到这一点。谢谢,这有效!我添加了loginContainer.setVisibility(View.GONE);在onAnimationEnd中,并且也将动画的持续时间从200更改为1000. – user1513171

+0

可能出现[显示和隐藏上下滑动动画的视图]的副本(http://stackoverflow.com/questions/19765938/show-and-用幻灯片向下看动画) –

回答

0

这里答案:

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

动画结束后,使布局无形