title: Setting custom ViewGroup/ composite View LayoutParameters inside its' constructor
body: <p>I'm extending the AppBarLayout to make my own version of it. My goal is it to set some LayoutParameters at runtime eg. the AppBar height.</p>
  
  <p>I get an NPE, if I try setting any Paramteres, I guess beause the LayoutParameters are not yet created and set.</p>
  
  <pre><code>public MyAppBar(Context context, AttributeSet attrs) {
      super(context, attrs);
      ...
  
      LayoutInflater.from(context).inflate(R.layout.layout_my_app_bar, this, true);
  
      ViewGroup.LayoutParams params = this.getLayoutParams();
      params.height = calculateExpandedHeight(selectedAspectRatio);
      this.setLayoutParams(params);
  
      ...
  }
  </code></pre>
  
  <p>My current workaround is it to set the <code>LayoutParams</code> inside <code>onMeasure</code>:</p>
  
  <pre><code>@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      if(!hasSetHeight) {
          ViewGroup.LayoutParams params = this.getLayoutParams();
          params.height = mExpandedHeight;
          this.setLayoutParams(params);
      }
  }
  </code></pre>
  
  <p>Is there a way to set the LayoutParameters inside the constructor of a custom ViewGroup / composite View?</p>
  
  <hr>
  
  <p><em>layout_my_app_bar.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;merge xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/tools"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:popupTheme="@style/AppTheme.PopupOverlay"/&gt;
  &lt;/merge&gt;
  </code></pre>