I met an issue when I expanded a 320*50 view to full-screen.
If I expand it directly, it works but the action is very abrupt and I think is not a good user experience. So I hide the view first, then expand it, and after two second, show the view again.
TextView.setVisibility(VIEW.INVISIBLE);
ViewGroup.LayoutParams lp = TextView.getLayoutParams();
lp.width = ViewGroup.LayoutParams.FILL_PARENT;
lp.height = ViewGroup.LayoutParams.FILL_PARENT;
//after two seconds
handler.postDelay(new Show(),2000);
class Show implements Runnable{
@Override
public void run(){
TextView.setVisibility(VIEW.VISIBLE);
}
}
So l left two seconds for the application to expand the view. Then after two seconds the view will show again. I am expected that the view is expanded to full-screen when it shows. But actually, it doesn't. The view do the expand action after it shows instead of during the two seconds it is hiding.
android:animateLayoutChanges="true"
to your ViewGroup
.setVisibility()
to control the visibility of your target View
.If there is other View
below you target View
, add android:animateLayoutChanges="true"
to your outer ViewGroup
and following code before setVisibility()
:
LayoutTransition layoutTransition = rootLinearLayout.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);