如何使用android数据绑定(bind)在xml中设置layout_weight?在 dimens 文件夹中,我们提供 dp/sp 中的值。
最佳答案
这是一个适合我的绑定(bind)适配器,你的 View 确实需要在 LinearLayout 中,我认为如果你想设置权重的话:
@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
}
}
关于安卓数据绑定(bind) : conditional formatting to set layout_weight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42270504/