title: Set dynamic layout height in data binding
body: <p>I want to set dynamic layout height in data binding structure.</p>
  
  <p>I tried something, but I get this exception:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
                    at databinding.ItemGroupCommentsBinding.executeBindings(ItemGroupCommentsBinding.java:147)
                    at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:355)
                    at view.base.adapter.DataBindingAdapter.onBindViewHolder(DataBindingAdapter.java:32)
                    at view.base.adapter.DataBindingAdapter.onBindViewHolder(DataBindingAdapter.java:15)
                    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6279)
                    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6312)
                    at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5258)
                    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5521)
                    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5363)
                    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5359)
                    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2141)
                    at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:556)
                    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1488)
                    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:585)
                    at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
                    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3506)
                    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3254)
                    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3767)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:636)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                    at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                    at android.view.View.layout(View.java:15604)
                    at android.view.ViewGroup.layout(ViewGroup.java:4966)
                    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                    at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
  </code></pre>
  
  <p>The code is: </p>
  
  <p><strong>Fragment.java</strong>:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      db = DataBindingUtil.inflate(inflater, R.layout.fragment_group_comments, container, false);
  
      getSubComponent().inject(this);
  
      db.setVariable(BR.height, 0);
  
      // Inflate the layout for this fragment
      return db.getRoot();
  }
  
  @BindingAdapter("android:layout_height")
  public static void setLayoutHeight(View view, float commentNumber) {
      Timber.e("setLayoutHeight " + commentNumber);
  
      try {
          GridLayoutManager.LayoutParams layoutParams =
                  (GridLayoutManager.LayoutParams) view.getLayoutParams();
  
          if (10 &lt;= commentNumber &amp;&amp; commentNumber &lt; 10) {
              layoutParams.height = 400;
          } else if (11 &lt;= commentNumber &amp;&amp; commentNumber &lt; 20) {
              layoutParams.height = 500;
          }
  
          view.setLayoutParams(layoutParams);
      } catch (Exception ignore) {}
  }
  </code></pre>
  
  <p><strong>item_.xml</strong></p>
  
  <pre><code>&lt;layout&gt;
  
  &lt;data&gt;
  
      &lt;variable
          name="height"
          type="Integer" /&gt;
  &lt;/data&gt;
  
  &lt;ScalingLayout
      android:id="@+id/view_item"
      style="@style/RelativeLayout_WrapContent"
      android:layout_height="@{height, default=wrap_content}"&gt;
  
      &lt;ImageView
          style="@style/ImageView_WrapContent"
          android:src="@mipmap/red_circle" /&gt;
  
  &lt;/ScalingLayout&gt;
  &lt;/layout&gt;
  </code></pre>