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?
LinearLayout. LayoutParams param = new LinearLayout. LayoutParams( 0, LayoutParams. MATCH_PARENT, 1);
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.
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.
Get the LinearLayout.LayoutParams
with getLayoutParams()
on a View
the parent of which is a LinearLayout
. The LayoutParams
object has a weight
field.
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
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