【问题标题】:LinearLayout does not set the required layout_height attributeLinearLayout 未设置所需的 layout_height 属性
【发布时间】:2012-06-05 16:03:38
【问题描述】:

我正在制作布局并应用一些样式。所以:

<style name="LayoutSmallMap">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">180dip</item>
        <item name="android:background">@drawable/rounded_corner</item>
        <item name="android:layout_margin">5dip</item>
        <item name="android:padding">3dip</item>
</style>

我用这个:

<LinearLayout 
       style="@style/LayoutSmallMap">

</LinearLayout>

但是当我在手机出现错误之前测试手机时,现在状态:

LinearLayout 未设置所需的 layout_height 属性

他没有找到我风格的属性?

不知道这是否是最好的解决方案,但它对我有用: 目标 SDK:2.3 和 minSdkVersion="7"

【问题讨论】:

    标签: android styles themes android-linearlayout


    【解决方案1】:

    您不应该在样式中使用 android:layout_width 和 android:layout_height。 修改你的代码如下。

    <style name="LayoutSmallMap">
            <item name="android:background">@drawable/rounded_corner</item>
            <item name="android:layout_margin">5dip</item>
            <item name="android:padding">3dip</item>
    </style>
    
    
    <LinearLayout 
           android:layout_width="fill_parent" 
           android:layout_height="180dip"  
           style="@style/LayoutSmallMap">
    
    </LinearLayout>
    

    【讨论】:

    • 我已经这样做了,这解决了我的问题,但我希望它是所有的风格,所以布局的源代码会更美观可视化。谢谢
    • @AderbalNunes 如何接受这个答案,我们只想要在这个布局中没有高度android:layout_width="fill_parent"android:layout_width="180dip" 这是可能的..
    • 是LinearLayout所必需的,不能只使用样式。
    【解决方案2】:

    试试这个

    <style name="LayoutSmallMap">         
        <item name="android:background">@drawable/rounded_corner</item>
        <item name="android:layout_margin">5dip</item>
        <item name="android:padding">3dip</item>
    </style>
    

    布局

    <LinearLayout 
        android:layout_width="fill_parent"
       android:layout_height="180dib"
        style="@style/LayoutSmallMap">
    
     </LinearLayout>
    

    【讨论】:

    • android:layout_width="fill_parent"android:layout_width="180dip"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2018-09-16
    • 1970-01-01
    • 2016-05-20
    • 2014-12-15
    • 2014-08-27
    • 2016-07-29
    相关资源
    最近更新 更多