I have similar question like this one: Update layout with the animation
Basically: I have one vertical LinearLayout View with edittext, button and then list. I'd like to hide exittext after pressing button to make more space for list (button will go up). On second press edittext should be visible again. Edittext and button have "wrap_content" height.
I'd like to hide and show edittext with animation.
I succeeded to animate hiding by overloading Animation's applyTransformation:
final float edittextheight= edittext.getHeight();
[....]
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t)
{
super.applyTransformation(interpolatedTime, t);
android.view.ViewGroup.LayoutParams lp = edittext.getLayoutParams();
lp.height = (int)(edittextheight*(1.0-interpolatedTime));
edittext.setLayoutParams(lp);
}
Problem:
I don't know how to calculate height to animate showing - edittext.getHeight(); returns 0 when widget is hidden and in layout definition I'm using "wrap_content".
Help?
You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.
Crossfade animations (also know as dissolve) gradually fade out one UI component while simultaneously fading in another. This animation is useful for situations where you want to switch content or views in your app. Crossfades are very subtle and short but offer a fluid transition from one screen to the next.
You can't get the height of edittext until activity finishes drawing it. So you can get it by adding onpredrawListner on your edit text.
ViewTreeObserver treeObserver = edittext.getViewTreeObserver();
treeObserver.addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
int height = edittext.getHeight();
ViewTreeObserver removeTreeObserver = edittext.getViewTreeObserver();
removeTreeObserver.removeOnPreDrawListener(this);
}
}
Now you got the height, apply any animation you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With