I'm trying to bind the width and height of my view but I can't see where's the problem.
I found this on this google issue
To implement these for your application, create a binding adapter:
@BindingAdapter("android:layout_width") public static void setLayoutWidth(View view, int width) { LayoutParams layoutParams = view.getLayoutParams(); layoutParams.width = width; view.setLayoutParams(layoutParams); }
So I created my Binding Adapter like this :
public class SimpleBindingAdapter {
@BindingAdapter("android:layout_width")
public static void setLayoutWidth(View view, int width) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = width;
view.setLayoutParams(layoutParams);
}
@BindingAdapter("android:layout_height")
public static void setLayoutHeight(View view, int height) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.height = height;
view.setLayoutParams(layoutParams);
}
//Others methods...
}
And then try to set my width and height like this :
<View
android:layout_width="@{paramsMessage.width}"
android:layout_height="@{paramsMessage.height}"
... />
Where paramsMessage.width is a public int attribute.
But I get this error :
Caused by: java.lang.RuntimeException: Binary XML file line #25: You must supply a layout_width attribute. at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:607) at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6761) at android.view.ViewGroup$MarginLayoutParams.(ViewGroup.java:6930) at android.widget.RelativeLayout$LayoutParams.(RelativeLayout.java:1244) at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1084) at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:83) at android.view.LayoutInflater.rInflate(LayoutInflater.java:820) at android.view.LayoutInflater.inflate(LayoutInflater.java:511) at android.view.LayoutInflater.inflate(LayoutInflater.java:415) at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:116) at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:88) at be.standard.appbusiness.tutorials.home.TutorialHomeFragment.onCreateDialog(TutorialHomeFragment.java:35) at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234) at android.app.Activity.performStart(Activity.java:6258) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5832) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
I would appreciate any helps on this, thank you !