Android Data Binding layout_width and layout_height

前端 未结 6 687
情话喂你
情话喂你 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 16:02

    According to the discussion on Android issue tracker, it is impossible to set layout height or width with data binding without creating custom binding adapters:

    https://code.google.com/p/android/issues/detail?id=180666

    The binding adapter needed for setting view height would look like that:

    @BindingAdapter("android:layout_height")
    public static void setLayoutHeight(View view, int height) {
        LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.height = height;
        view.setLayoutParams(layoutParams);
    }
    

提交回复
热议问题