How to get layout_weight programmatically?

I have a simple question: how to get layout_weight programmatically? I saw a lot of topics when some Layoute set layout_weight, but how to get it?

+4
source share
2 answers

Get LinearLayout.LayoutParamsfrom getLayoutParams()to Viewwhose parent is LinearLayout. The object LayoutParamshas a field weight.

+6
source

this is the answer:

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

this value will return the weight of your View to you and notice that your view should be in linear mode and have a weight of up to

+2
source

All Articles