Setting layout_width, layout_height using style

I used a style file to set a unique style for the 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 the layout file

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

Error:(design time)

enter image description here

Runtime Error:

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 am I going wrong? TIA

+6
source share
2 answers

EDIT I checked your script. It seems that layout_width and layout_height should be set according to the layout. If you do not want to mention them in xml, specify it in the style.xml file and use to view it.

+3
source

Even I had the same problem as I decided, just to provide wrap_content both in height and in width in the layout XML file . Then override any height and width in the xml style file , so now you do not need to change the value again in the XML layout file. Finally, just add the style attribute to the appropriate view.

0
source

Source: https://habr.com/ru/post/947188/


All Articles