title: Child Views Taking too much time to draw on screen
body: <p>I have android layout design in which I have an <code>AppBar</code> layout which will contain a <code>Toolbar</code> and one more <code>LinearLayout</code> design with circle <code>Drawable</code> as <code>TextView</code>. which is off same height. So when I try to get the <code>Toolbar</code> or <code>AppBar</code> height/width it's returning only 0. </p>
  
  <p><strong>activity_main.xml:</strong>
      
      </p>
  
  <pre><code>    &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/app_bar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?actionBarSize"
              android:background="@color/colorPrimary"
              app:layout_scrollFlags="enterAlways" /&gt;
         &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="?actionBarSize"
              android:layout_gravity="center_horizontal"
              android:background="@color/colorPrimary"
              android:orientation="horizontal"
              app:layout_scrollFlags="enterAlways"&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginLeft="2dp"
                  android:layout_weight="1"
                  android:orientation="horizontal"&gt;
  
                  &lt;TextView
                      android:id="@+id/marked_questions"
                      style="@style/textview_summary_omr_toolbar_count"
                      android:background="@drawable/bg_percentage_default"
                      android:text="18" /&gt;
  
                  &lt;TextView
                      style="@style/textview_heading_summary_omr_toolbar"
                      android:text="Marked" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginLeft="2dp"
                  android:layout_weight="1"
                  android:orientation="horizontal"&gt;
  
                  &lt;TextView
                      android:id="@+id/correct"
                      style="@style/textview_summary_omr_toolbar_count"
                      android:background="@drawable/bg_percentage_6"
                      android:text="18"
  
                      /&gt;
  
                  &lt;TextView
                      style="@style/textview_heading_summary_omr_toolbar"
                      android:text="Correct" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginLeft="2dp"
                  android:layout_weight="1"
                  android:orientation="horizontal"&gt;
  
                  &lt;TextView
                      android:id="@+id/wrong"
                      style="@style/textview_summary_omr_toolbar_count"
                      android:background="@drawable/bg_percentage_wrong"
                      android:text="18" /&gt;
  
                  &lt;TextView
                      style="@style/textview_heading_summary_omr_toolbar"
                      android:text="Wrong" /&gt;
              &lt;/LinearLayout&gt;
  
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginLeft="2dp"
                  android:layout_weight="1"
                  android:orientation="horizontal"&gt;
  
                  &lt;TextView
                      android:id="@+id/conflicts"
                      style="@style/textview_summary_omr_toolbar_count"
                      android:background="@drawable/bg_percentage_3"
                      android:text="0" /&gt;
  
                  &lt;TextView
                      style="@style/textview_heading_summary_omr_toolbar"
                      android:text="Conflicts" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginLeft="2dp"
                  android:layout_weight="1"
                  android:orientation="horizontal"&gt;
  
                  &lt;TextView
                      style="@style/textview_summary_omr_toolbar_count"
                      android:text="Score:"
                      android:textColor="@android:color/white" /&gt;
  
                  &lt;TextView
                      android:id="@+id/marks_scored"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_vertical"
                      android:gravity="center"
                      android:text="18/30"
                      android:textColor="@android:color/white"
                      android:textSize="18sp" /&gt;
  
              &lt;/LinearLayout&gt;
  
  
          &lt;/LinearLayout&gt;
      &lt;/android.support.design.widget.AppBarLayout&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java:</strong>
  Here I am initializing the <code>Toolbar</code> and <code>AppBar</code> and try to print the width and height of both in logs ,which is returning me zero. </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private AppBarLayout app_bar;
  protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         app_bar = (AppBarLayout) findViewById(R.id.app_bar);
         toolbar = (Toolbar) findViewById(R.id.toolbar);
         logToolbarLayoutParams();
  
  }
  private void logToolbarLayoutParams() {
          Log.d(TAG,"Toolbar width/Height"+this.toolbar.getWidth()+"/"+this.toolbar.getHeight());
          Log.d(TAG,"App_bar width/height"+this.app_bar.getWidth()+"/"+this.app_bar.getHeight());
  
  }
  </code></pre>
  
  <p>I have also referred to this question in the <a href="https://stackoverflow.com/questions/3591784/getwidth-and-getheight-of-view-returns-0">stackoverflow</a>.</p>
  
  <pre><code>final AppBarLayout app_bar = (AppBarLayout) findViewById(R.id.app_bar);
                  ViewTreeObserver vto = app_bar.getViewTreeObserver();
                  vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                      @Override
                      public void onGlobalLayout() {
                          app_bar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                          Log.d(TAG, "Global layout");
                          logToolbarLayoutParams();
              }
          });
  </code></pre>
  
  <p>If I add the following code in  my <code>MainActivity</code> it's getting me the proper height and width of <code>Toolbar</code>. From the stackoverflow question which I mentioned before, I came to know that, the views were not drawn on the screen, so I have to wait. But my doubt here is, the design which i have specified is not a complex one? 
  why its taking much time to draw on screen? am I missing something?</p>
  
  <p>I have used Hierarchy Viewer to find out, what's making the child layout to load slowly. I found that I am using mulitple <code>LinearLayout</code> where single <code>RelativeLayout</code> can be used to obtain the same structure. I have changed my layout design as the following. 
  Still I am facing the same issue. </p>
  
  <p>updated: <strong>activity_main.xml:</strong></p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/app_bar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?actionBarSize"
              android:background="@color/colorPrimary"
              app:layout_scrollFlags="enterAlways" /&gt;
     &lt;RelativeLayout
           android:id="@+id/summary_bottom_sheet"
           android:layout_width="match_parent"
           android:layout_height="?actionBarSize"
           android:layout_gravity="center_horizontal"
           android:background="@color/colorPrimary"&gt;
  
  
           &lt;TextView
               android:id="@+id/marked_questions"
               style="@style/textview_summary_omr_toolbar_count"
               android:layout_alignParentLeft="true"
               android:layout_alignParentStart="true"
               android:background="@drawable/bg_percentage_default"
               android:text="18" /&gt;
  
           &lt;TextView
               android:id="@+id/marked_textview"
               style="@style/textview_heading_summary_omr_toolbar"
               android:layout_toEndOf="@+id/marked_questions"
               android:layout_toRightOf="@+id/marked_questions"
               android:text="Marked" /&gt;
  
  
           &lt;TextView
               android:id="@+id/correct"
               style="@style/textview_summary_omr_toolbar_count"
               android:layout_toEndOf="@+id/marked_textview"
               android:layout_toRightOf="@+id/marked_textview"
               android:background="@drawable/bg_percentage_6"
               android:text="18"
  
               /&gt;
  
           &lt;TextView
               android:id="@+id/correct_textview"
               style="@style/textview_heading_summary_omr_toolbar"
               android:layout_toEndOf="@+id/correct"
               android:layout_toRightOf="@+id/correct"
               android:text="Correct" /&gt;
  
  
           &lt;TextView
               android:id="@+id/wrong"
               style="@style/textview_summary_omr_toolbar_count"
               android:layout_toEndOf="@+id/correct_textview"
               android:layout_toRightOf="@+id/correct_textview"
               android:background="@drawable/bg_percentage_wrong"
               android:text="18" /&gt;
  
           &lt;TextView
               android:id="@+id/wrong_textview"
               style="@style/textview_heading_summary_omr_toolbar"
               android:layout_toEndOf="@+id/wrong"
               android:layout_toRightOf="@+id/wrong"
               android:text="Wrong" /&gt;
  
  
           &lt;TextView
               android:id="@+id/conflicts"
               style="@style/textview_summary_omr_toolbar_count"
               android:layout_toEndOf="@+id/wrong_textview"
               android:layout_toRightOf="@+id/wrong_textview"
               android:background="@drawable/bg_percentage_3"
               android:text="0" /&gt;
  
           &lt;TextView
               android:id="@+id/conflicts_textview"
               style="@style/textview_heading_summary_omr_toolbar"
               android:layout_toEndOf="@+id/conflicts"
               android:layout_toRightOf="@+id/conflicts"
               android:text="Conflicts" /&gt;
  
  
           &lt;TextView
               android:id="@+id/score_textview"
               style="@style/textview_summary_omr_toolbar_count"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_toEndOf="@+id/conflicts_textview"
               android:layout_toRightOf="@+id/conflicts_textview"
               android:background="@null"
               android:gravity="center"
               android:text="Score:"
               android:textColor="@android:color/white" /&gt;
  
           &lt;TextView
               android:id="@+id/marks_scored"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_centerVertical="true"
               android:layout_gravity="center_vertical"
               android:layout_toEndOf="@+id/score_textview"
               android:layout_toRightOf="@+id/score_textview"
               android:gravity="center"
               android:text="18/30"
               android:textColor="@android:color/white"
               android:textSize="18sp" /&gt;
     &lt;/RelativeLayout&gt;
   &lt;/android.support.design.widget.AppBarLayout&gt;
   &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>The following is the hierarchy viewer <a href="https://i.stack.imgur.com/njcvV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/njcvV.png" alt="Hierarchy_viewer"></a> Image I am obtaining</p>