Android Data Binding layout_width and layout_height

前端 未结 6 698
情话喂你
情话喂你 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:40

    In Java

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

    And in your XML

    app:layout_height="@{ viewModel.isBig ? @dimen/dp_20 : @dimen/dp_5 }"
    

    import the app like this

    xmlns:app="http://schemas.android.com/apk/res-auto"
    

提交回复
热议问题