【问题标题】:cannot set height and width of a resource shape in styles无法在样式中设置资源形状的高度和宽度
【发布时间】:2011-09-17 10:21:57
【问题描述】:

我最近制作了我的第一个自定义形状,结果非常好接受一件事。我似乎无法在样式资源中设置可绘制资源的高度和 with。

我没有指定 på 形状的高度或宽度,因为我想以不同的尺寸使用这个形状。所以我在我的styles.xml 文件中设置了高度和宽度。但最终的结果是看起来像我不想要的使用 wrap_content 作为高度和宽度的形状。

非常感谢任何帮助!

形状 - list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle" >

        <solid 
            android:color="@color/list_item_background"
        />

    </shape>
</item>
<item>
    <shape android:shape="rectangle" >

        <gradient 
            android:angle="270"
            android:startColor="@color/list_item_gradient_white"
            android:endColor="@color/list_item_gradient_black"
            android:type="linear"
        />

        <stroke 
            android:color="@color/list_item_stroke"
            android:width="1px"
        />

    </shape>
</item>

风格

<style name="SmallListItem">
    <item name="android:background">@drawable/list_item</item>
    <item name="android:layout_height">69.5dip</item>
    <item name="android:layout_width">fill_parent</item>
</style>

【问题讨论】:

    标签: android height width shape


    【解决方案1】:

    试试这样的:

    <ImageView
        style="@style/SmallListItem"
        android:src="@drawable/list_item" />
    

    请参阅http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList 了解有关如何使用图层列表的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-09
      • 2012-05-02
      • 2011-08-17
      • 2018-09-02
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多