Reputation: 4152
I will try to describe what I want the more precisely I can. I am pretty sure it can be done with a simple animation but I can't really find the words to describe the behavior I am waiting for.
I am currently displaying a LinearLayout
containing two other LinearLayout
childs. The parent's gravity is set to center
.
I am able to switch the first child visibility from GONE
to VISIBLE
and vice-versa, when clicking on a button.
If the first child layout
is set to GONE
and I change it to VISIBLE
, it will appear on the screen and the second
child will move to the bottom to give some space. (as the gravity is set to center).
That's what I'd like to animate, when the second child moves to the top/bottom, to let the first one appear / disappear, so it's not instantaneous but smooth.
Here is an animated GIF that shows the whole thing :
Upvotes: 0
Views: 381
Reputation: 4152
I finally found that a animation can be applied to my layouts, in order to animate their moves :
LayoutTransition rpTransition = layout.getLayoutTransition();
rpTransition.enableTransitionType(LayoutTransition.CHANGING);
Upvotes: 1
Reputation: 1710
This is how I would do this :
//in onCreate
fadingView.setAlpha(0);
...
public void fadeThenSlide (final View fadingView, final View slidingView ){
slidingView.animate().translationYBy(fadingView.getHeight()).
setDuration(200).
setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
fadingView.animate().alpha(1).setDuration(200);
}
});
}
I haven't tested the code yet so there might be some problems, you can try it and tell me
Upvotes: 0