Android数据绑定:条件格式设置layout_weight

时间:2021-11-05 04:53:27

How to set layout_weight in xml using android data bindning? in dimens folder we provide values as in dp / sp.

如何使用android数据绑定在xml中设置layout_weight?在dimens文件夹中,我们提供dp / sp中的值。

2 个解决方案

#1


0  

Use the same technique as for android:layout_width and android:layout_height, which has been discussed previously:

使用与android:layout_width和android:layout_height相同的技术,这已在前面讨论过:

How to bind a layout_width and layout_height using data binding in Android

如何在Android中使用数据绑定绑定layout_width和layout_height

You must create your own BindingAdapter.

您必须创建自己的BindingAdapter。

#2


-1  

Try this:

尝试这个:

@BindingAdapter("layout_weight")
    fun setLayoutWeight(view: View, weight: Float) {
        view.layoutParams = TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
                                                     TableLayout.LayoutParams.WRAP_CONTENT,
                                                     weight)
    }

#1


0  

Use the same technique as for android:layout_width and android:layout_height, which has been discussed previously:

使用与android:layout_width和android:layout_height相同的技术,这已在前面讨论过:

How to bind a layout_width and layout_height using data binding in Android

如何在Android中使用数据绑定绑定layout_width和layout_height

You must create your own BindingAdapter.

您必须创建自己的BindingAdapter。

#2


-1  

Try this:

尝试这个:

@BindingAdapter("layout_weight")
    fun setLayoutWeight(view: View, weight: Float) {
        view.layoutParams = TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
                                                     TableLayout.LayoutParams.WRAP_CONTENT,
                                                     weight)
    }