无法在样式中设置资源形状的高度和宽度

时间:2011-06-17 18:42:16

标签: android height width shape

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

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

非常感谢任何帮助!

SHAPE - 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>

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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

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