title: Android : inflate() ignoring utilizing root layout width/height defined in style sheets. BInary XML error
body: <p>I'm working on a project, and I'm converting the GUI over to Style sheets.  I use a layout, and then a landscape/portrait set of style sheets.  I use an inflator to inflate the layout, as I am dynamically adding and removing content, and the view itself is dynamically created and destroyed by an application which my code plugs into.</p>
  
  <pre><code>myView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.bearing_layout, parentView, false);
  </code></pre>
  
  <p>Error:  Java.Lang.RuntimeException: Binary XML file, line 2: You must supply a layout_width attribute. </p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      style="@style/bearing_overall_layout"&gt;
      &lt;LinearLayout 
          style = "@style/bearing_header_layout"&gt;
          &lt;TextView android:id="@+id/header" 
              style = "@style/bearing_header"
              android:background="@drawable/transparentbackground"
              android:text="@string/bearing_title" /&gt;
      &lt;/LinearLayout&gt;
      &lt;RelativeLayout style="@style/BearingSelectListContainer"
          android:id="@+id/top_view"&gt;
          &lt;LinearLayout 
              style="@style/BearingSelectList_linear_layout"&gt;
              &lt;TextView style="@style/BearingSelectListTitle" 
                  android:id="@+id/title"
                  android:text="@string/bearing_title" /&gt;
              &lt;ScrollView android:id="@+id/listScroller"
                  style="@style/bearing_list_scroller"&gt;
                  &lt;LinearLayout
                      style="@style/bearing_scroll_list_linear_layout" &gt;
                      &lt;LinearLayout android:id="@+id/pointList"
                          style="@style/bearing_point_list"&gt;
                      &lt;/LinearLayout&gt;
                  &lt;/LinearLayout&gt;
              &lt;/ScrollView&gt;
          &lt;LinearLayout 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" 
                  android:layout_gravity="center_horizontal"&gt;
                  &lt;Button style="@style/BearingSelectListButton" android:id="@+id/view" android:text="@string/view_button" /&gt;
                  &lt;Button style="@style/BearingSelectListButton" android:id="@+id/my_loc" android:text="@string/my_loc_button" /&gt;
                  &lt;Button style="@style/BearingSelectListButton" android:id="@+id/center" android:text="@string/center_button" /&gt;
                  &lt;Button style="@style/BearingSelectListButton" android:id="@+id/exit" android:text="@string/exit_button" /&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And the style sheet:</p>
  
  <pre><code>&lt;resources&gt;
  &lt;style name="bearing_overall_layout"&gt;
      &lt;item name="android:orientation"&gt;vertical&lt;/item&gt;
      &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;300dp&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name = "bearing_header_layout"&gt;
      &lt;item name ="android:orientation"&gt;horizontal&lt;/item&gt;
      &lt;item name ="android:layout_width"&gt;fill_parent&lt;/item&gt;
      &lt;item name ="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name ="android:layout_alignParentTop"&gt;true&lt;/item&gt;
      &lt;item name ="android:gravity"&gt;center&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="bearing_header"&gt;
      &lt;item name = "android:padding"&gt;10dp&lt;/item&gt;
      &lt;item name = "android:textSize"&gt;18sp&lt;/item&gt;
      &lt;item name = "android:textStyle"&gt;bold&lt;/item&gt;
      &lt;item name = "android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name = "android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name = "android:layout_alignParentTop"&gt;true&lt;/item&gt;
      &lt;item name = "android:gravity"&gt;center&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="GotoMgrsInput"&gt;
      &lt;item name="android:textSize"&gt;18dp&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_width"&gt;300dp&lt;/item&gt;
      &lt;item name="android:background"&gt;#ff000000&lt;/item&gt;
  &lt;/style&gt;
      &lt;style name="BearingSelectMgrsInput"&gt;
      &lt;item name="android:textSize"&gt;16sp&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_weight"&gt;1&lt;/item&gt;
      &lt;item name="android:typeface"&gt;monospace&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="bearing_list_scroller"&gt;
      &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt; 
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_weight"&gt;1&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;
  
  &lt;/style&gt;
  &lt;style name = "bearing_scroll_list_linear_layout"&gt;
      &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt;
      &lt;item name="android:orientation"&gt;vertical&lt;/item&gt;
      &lt;item name="android:layout_marginBottom"&gt;10dp&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;  
  &lt;/style&gt;
  &lt;style name = "bearing_point_list"&gt;
      &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt; 
      &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt;
      &lt;item name="android:layout_marginRight"&gt;1dip&lt;/item&gt;
      &lt;item name="android:orientation"&gt;vertical&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;
  &lt;/style&gt;
  
  &lt;style name="bearing_BearingSelectListContainer"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt;
      &lt;item name="android:background"&gt;#a000&lt;/item&gt;
      &lt;item name="android:layout_alignParentLeft"&gt;true&lt;/item&gt;
      &lt;item name="android:id"&gt;@+id/top_view&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;
      &lt;item name="android:layout_alignParentLeft"&gt;false&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="BearingSelectList_linear_layout"&gt;
      &lt;item name="android:orientation"&gt;vertical&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt; 
      &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt;
  
  &lt;/style&gt;
  &lt;style name="BearingSelectListTitle"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_gravity"&gt;center&lt;/item&gt;
      &lt;item name="android:textStyle"&gt;bold&lt;/item&gt;
      &lt;item name="android:textSize"&gt;24sp&lt;/item&gt;
  &lt;/style&gt;    
  &lt;style name="bearing_BearingSelectListButton"&gt;
      &lt;item name="android:layout_width"&gt;80dp&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="bearing_text_label"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_gravity"&gt;center&lt;/item&gt; 
      &lt;item name="android:shadowColor"&gt;#ff000000&lt;/item&gt; 
      &lt;item name="android:shadowDx"&gt;1&lt;/item&gt;
      &lt;item name="android:shadowDy"&gt;1&lt;/item&gt; 
      &lt;item name="android:shadowRadius"&gt;1&lt;/item&gt; 
      &lt;item name="android:textStyle"&gt;bold&lt;/item&gt;
      &lt;item name="android:clickable"&gt;false&lt;/item&gt; 
      &lt;item name="android:longClickable"&gt;false&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="bearing_item_inner_layout"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:gravity"&gt;center&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="bearing_specific_view_layout"&gt;
      &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
      &lt;item name="android:orientation"&gt;horizontal&lt;/item&gt;
      &lt;item name="android:layout_alignParentLeft"&gt;true&lt;/item&gt;
  &lt;/style&gt; 
  </code></pre>
  
  <p></p>
  
  <p>Now if I hard define the android:width and android:height in the base layout everything else runs perfectly.    This isn't really acceptable because I need different values for layout vs portrait, as well as for different builds of phones.</p>
  
  <p>The next option is to set the rootView of inflate to null, which does get the layout params right (sort of...), BUT this causes null pointers when I try and access internal elements of the view which is returned.</p>
  
  <p>It seems to me like inflate is just ignoring the style elements of the inflated view, and from this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/5026926/making-sense-of-layoutinflater">Why does LayoutInflater ignore the layout_width and layout_height layout parameters I&#39;ve specified?</a></p>
  
  <p>I see why, but again this doesn't do me any good in this case as I've attempted the suggested approaches (see above) and I am still getting this error when using style sheets.</p>
  
  <p>The only option I haven't tried is hard coding the values into the layout, and then programatically detecting the orientation of the screen and altering the layout params accordingly, but again this would need to be done for a variety of phone builds and seems to defeat the entire purpose of style sheets.</p>
  
  <p>Anyone have any ideas?</p>