安卓数据绑定(bind) : conditional formatting to set layout_weight

标签 android android-databinding

如何使用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/

相关文章:

java - 无法让我的 DialogFragment 背景透明

android - 在 Android Studio 的数据绑定(bind)库中找不到 setHandler 的符号方法

android - 数据绑定(bind) onClick 不起作用

android - android数据绑定(bind)中的 "DataBindingComponent"类是什么?

android - 在 Android OpenglES 2.0 中加载压缩纹理

android - Cocos2d-x 应用程序无法为 Android 编译

android - 如何通过用户输入将谷歌地图设置为地址

java - CustomControl,xml 属性不适用于数据绑定(bind)

android - actionSearch Edittex 上的数据绑定(bind)

android - 例程 :EVP_DecryptFinal_ex:wrong final block length in android