Android Data Binding layout_width and layout_height

前端 未结 6 700
情话喂你
情话喂你 2020-12-08 15:12

I need to be able to dynamically set an EditText\'s height property. I am using data binding for other properties throughout my app, so I would love to be able to use data b

6条回答
  •  忘掉有多难
    2020-12-08 15:53

    I solved it like this in Kotlin instead of Java.

    Make a file called

    MyBindings.kt
    

    And put in:

    @BindingAdapter("bind:customHeight")
    fun setLayoutHeight(view: View, height: Float) {
        view.layoutParams = view.layoutParams.apply { this.height = height.toInt() }
    }
    

    And then you can use this in your layouts:

    
    

提交回复
热议问题