Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get layout_weight programmatically?

Tags:

android

layout

I have simple question: How to get layout_weight programmatically? I seen many topics, when some Layoute set layout_weight, but how to get it?

like image 816
user2257161 Avatar asked Dec 08 '13 19:12

user2257161


People also ask

How do you set linear layout weight programmatically?

LinearLayout. LayoutParams param = new LinearLayout. LayoutParams( 0, LayoutParams. MATCH_PARENT, 1);

What does layout_weight mean in android?

LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.

What is layout params?

LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes for a list of all child view attributes that this class supports. The base LayoutParams class just describes how big the view wants to be for both width and height.


Video Answer


2 Answers

Get the LinearLayout.LayoutParams with getLayoutParams() on a View the parent of which is a LinearLayout. The LayoutParams object has a weight field.

like image 122
laalto Avatar answered Sep 22 '22 17:09

laalto


this is answer:

((LinearLayout.LayoutParams)yourView.getLayoutParams()).weight

this value will return you weight of yourView and notice that your view should be in a linearlayout and had a weight before

like image 22
saleh sereshki Avatar answered Sep 23 '22 17:09

saleh sereshki