Android幻灯片进/出布局与动画

时间:2013-01-09 13:26:30

标签: java android animation slidedown

我已经搜索了很多关于这个问题的信息。

我有一个包含3个LinearLayouts的LinearLayout。

第一个就像是第二个的标题。 最后一个只是其他一些内容。

我现在不想向上/向下滑动第二个布局。 使用此代码可以正常工作:

滑下:

Animation a = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.show_zeiten); 
                a.setFillAfter(true); 
                zeiten_sonstigeZeiten_Layout.startAnimation(a); 
                zeiten_sonstigeZeiten_Layout.setVisibility(View.VISIBLE);

我的问题是,当动画开始时,3 Layout会立即跳转到新位置。 我希望实现3.布局顺利滑下第二个布局。

我的动画

<set xmlns:android="http://schemas.android.com/apk/res/android"  
android:fillEnabled="true"  
android:interpolator="@android:anim/accelerate_interpolator" >  
<translate       
      android:duration="@android:integer/config_mediumAnimTime"    
      android:fromYDelta="-100%"      
         android:toYDelta="0" /> 

有没有人暗示我怎么能做出这种行为?

感谢您的帮助! 最好的祝福 schwandi

编辑:

我尝试添加一个animationListener,但没有一个方法被调用:

Animation a = AnimationUtils.loadAnimation(context, R.anim.show_zeiten); 
                a.setFillAfter(true); 

                a.setAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        Log.e(TAG,"onAnimationStart");
                                }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        Log.e(TAG,"onAnimationRepeat");
                                }

                    @Override
                    public void onAnimationEnd(Animation animation) {

                        Log.e(TAG,"onAnimationEnd");
                        zeiten_sonstigeZeiten_Layout.setVisibility(View.VISIBLE);

                                }
                });


                zeiten_sonstigeZeiten_Layout.startAnimation(a); 

1 个答案:

答案 0 :(得分:3)

动画开始时您正在进行更改。 最好的方法是添加AnimationListener并在动画结束后进行布局更改。

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

        @Override
        public void onAnimationRepeat(Animation animation) {
                    }

        @Override
        public void onAnimationEnd(Animation animation) {
            // setLayoutParams here 
                    }
    });