How to set layout_weight in xml using android data bindning? in dimens folder we provide values as in dp / sp.
This is a binding adapter that works for me, your view does need to be inside a LinearLayout, which I think it will be if you are wanting to set the weight:
@BindingAdapter("android:layout_weight")
fun setLayoutWeight(view: View, weight: Float) {
val layoutParams = view.layoutParams as? LinearLayout.LayoutParams
layoutParams?.let {
it.weight = weight
view.layoutParams = it
}
}
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