使用样式设置layout_width,layout_height

vns*_*tty 8 layout android android-layout android-linearlayout

我使用样式文件为相同的布局设置了一个独特的样式,

样式:

<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 >
Run Code Online (Sandbox Code Playgroud)

//在布局文件中

 <LinearLayout
   style="@style/UserFormLayoutRow" >
         //contents
 </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Error:(design 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.

我哪里错了?TIA

Pra*_*chi 4

编辑我检查了你的场景。看来layout_width和layout_height必须在layout下定义。如果您不想在 xml 中提及它们,请在 style.xml 中提及并将其用于您的视图。

  • 你能给我推荐一个官方链接吗 (6认同)