https://blog.csdn.net/zhuhai__yizhi/article/details/52921374
一、定义绑定视图适配器
@BindingAdapter("android:layout_width")
public static void setLayoutWidth(View view, float width) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = (int) width;
view.setLayoutParams(params);
}
@BindingAdapter("android:layout_height")
public static void setLayoutHeight(View view, float height) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = (int) height;
view.setLayoutParams(params);
}
二、xml绑定
注意两点:1)只能绑定dimen值 2)要绑定default值
<TextView
android:layout_width="@{@dimen/text_width, default=@dimen/text_width}"
android:layout_height="@{@dimen/text_height, default=@dimen/text_height}"
android:background="#e6e6e6"
android:gravity="center"
android:text="my girl!" />
0 条评论