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

标签 android height width shapes

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

我没有在 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>

最佳答案

尝试这样的事情:

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

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

关于android - 无法在样式中设置资源形状的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6390296/

相关文章:

flash - 如何在 AS3 中设置 swf 的宽度和高度?

CSS - 从最后一个之前的DIV获取宽度

安卓 :The unit of imageLayout. getHeight

android - AsyncTask不会在Android 2.3 Andengine中引发异常

android - 滚动时自定义 ListView 中的错误

javascript - 从 Cordova 应用程序打开 native 谷歌地图

c - 在C中获取终端宽度?

android - 有超时的Android InputStream类吗?

Java - 如何自动设置 img.getScaledInstance( ); 的宽度?

css - 简单的 CSS 布局