Reputation: 231
i have googled a lot about this problem.
I have a LinearLayout with 3 LinearLayouts in it.
The first one is like a header for the second one. And the last one is just some other content.
I now wan´t to slide up/down the second Layout. That works fine with this code:
For sliding down:
Animation a = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.show_zeiten);
a.setFillAfter(true);
zeiten_sonstigeZeiten_Layout.startAnimation(a);
zeiten_sonstigeZeiten_Layout.setVisibility(View.VISIBLE);
My problem is that the 3 Layout immediately jumps done to his new position when the animation starts. I would like to achieve that the 3. Layout slides down below the second one smoothly.
My animation
<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" />
Has anyone a hint how i can make this behavior?
Thank you for your help! Best regards schwandi
EDIT:
i have tryed to add a animationListener, but none of the methods gets called:
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);
Upvotes: 1
Views: 1417
Reputation: 6588
You are making the changes when the animation starts.
The best method is to add an AnimationListener
and do the layout changes once the animation ends.
yourAnimationObject.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// setLayoutParams here
}
});
Upvotes: 3