Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change LinearLayout height to 0 programmatically

I am resizign LinearLayout from it's original height to 0 with:

ViewGroup.LayoutParams params = getLayoutParams();
params.height = newHeight;
requestLayout();

Everything works except newHeight = 0 - layout's height changes back to its original height. How can I avoid it ?

Setting visibility to GONE if newHeight == 0 does not help.

like image 919
hsz Avatar asked Sep 03 '12 09:09

hsz


People also ask

How do I fix the view to the bottom of LinearLayout?

This can also be done with a linear layout. Just provide Height = 0dp and weight = 1 in the layout above, and the one you want at the bottom is just write height = line feed content, not weight.

Is LinearLayout deprecated?

This constant was deprecated in API level 28.

How do you align text in LinearLayout?

To center align LinearLayout, assign android:gravity attribute of this LinearLayout with the value “center”. Let us create an Android application with LinearLayout containing two Button widgets as children. We shall center align these children using gravity attribute.


1 Answers

Try this.....

 LinearLayout layout = (LinearLayout)findViewById(R.id.yourLayoutId);

 LinearLayout.LayoutParams lp = (LayoutParams) layout.getLayoutParams();
 lp.height = 0;
like image 62
Mehul Santoki Avatar answered Sep 19 '22 10:09

Mehul Santoki