Android Data Binding layout_width and layout_height

前端 未结 6 699
情话喂你
情话喂你 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条回答
  •  猫巷女王i
    2020-12-08 15:57

    For me did this the trick:

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

    And the xml:

    android:layout_height="@{item.isItemCollapsed ? @dimen/radar_item_first_background_height  : item.textMaxLines, default=@dimen/radar_item_first_background_height}"
    

提交回复
热议问题