9

I used a style file to set a unique style for same layouts,

Style:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
   <!-- User form layout style -->
   <style name="UserFormLayoutRow">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:orientation">horizontal</item>
    <item name="android:paddingBottom">@dimen/padding_small</item>
   </style>
</resources >

//In layout file

 <LinearLayout
   style="@style/UserFormLayoutRow" >
         //contents
 </LinearLayout>

Error:(design time)

enter image description here

Error at run time:

06-13 05:58:14.506: E/AndroidRuntime(936): Caused by: java.lang.RuntimeException: Binary XML file line #105: You must supply a layout_width attribute.

Where i am going wrong? TIA

vnshetty
  • 20,051
  • 23
  • 64
  • 102
  • 1
    you should specify the linear layout width and height.i guess you have not done that – Raghunandan Jun 13 '13 at 06:25
  • 1
    @ Raghunandan i specified it in style file right? i dnt like to again writing same thing..Assume hve hundred linear layout, so i want to put it in style file and get it from there? – vnshetty Jun 13 '13 at 06:27
  • What's your min and target SDK version in manifest? – laalto Jun 13 '13 at 06:29
  • The same works for me are you sure the line #105 have the same LinearLayout ? – Triode Jun 13 '13 at 06:35
  • 1
    Do you just have it defined in the `res\values` folder, but not in the `values-v11` and `values-v14` folders? You might try to define them in those 2 folders as well according to [this](http://stackoverflow.com/questions/4947720/android-theme-not-being-set?lq=1) question. – Shobhit Puri Jun 13 '13 at 06:40
  • @Shobhit Puri still no luck – vnshetty Jun 13 '13 at 06:53
  • Only some other minor issues seen here that do not cause this behavior: `LinearLayout` close tag missing, `//` is not a valid comment for xml, `xmlns:android` is not needed for `values` resources. So, since what you posted works for others, there's something missing from the question. – laalto Jun 13 '13 at 07:03
  • Go through with this link [enter link description here](http://stackoverflow.com/questions/16497758/why-shouldnt-i-set-layout-width-and-layout-height-in-a-style/34761308#34761308) – Raja Jawahar Jan 13 '16 at 08:08

2 Answers2

4

EDIT I checked for your scenario. It appears that layout_width and layout_height must be given defined under layout. If you do not want to mention them in xml, then mention it in style.xml and use it for your view.

Prachi
  • 3,584
  • 2
  • 24
  • 39
  • 6
    can you please refer me a official link on this – vnshetty Jun 21 '13 at 03:52
  • 1
    @RajaJawahar, I am facing a problem, when I apply layout_width and layout_height using styles.xml and above mentioned styles not applying in view.Can you provide some sample code or where am I missing anything? – BABU K Feb 02 '17 at 14:14
0

Even i had this same problem, the way i solved is just provide wrap_content to both height and width in the layout xml file. Then override whatever height and width you want in the style xml file, so now you need not change the value again in layout xml file. At last just add the style attribute to the corresponding view.

Ravi Raj
  • 6,247
  • 2
  • 30
  • 32