How do I resize the LinearLayout when it is executed?

How to resize a LinearLayout at runtime?

I set the size dynamically when it's runtime. But no luck. Didn't resize LinearLayout.

How do I code it?

Thanks in advance.

+2


a source to share


2 answers


The size is determined LayoutParams

by connecting LinearLayout

to its parent.



+3


a source


This is how I do it:



// get element I want to resize
LinearLayout myBar = (LinearLayout) findViewById(R.id.infopanel_graph); 

// get layout parameters for that element
ViewGroup.LayoutParams params = myBar.getLayoutParams();

// change width of the params e.g. 50dp
params.width = 50;

// initialize new parameters for my element
myBar.setLayoutParams(new LinearLayout.LayoutParams(params));

      

+3


a source







All Articles