无法在样式中设置资源形状的高度和宽度
我最近做了我的第一个自定义形状,结果真的很好接受一件事。我似乎无法在样式资源中设置可绘制资源的高度和宽度。
我没有指定形状的高度或宽度,因为我想在不同的尺寸中使用这个形状。所以我在 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>
I recently made my first custom shape and it turned out really good accept one thing. i can't seem to set the height and with of the drawable resource in a style resource.
I do not specify a height or width in på shape because i want to use this shape in different sizes. So i set height and width in my styles.xml file. But the final result is what looks like the shape using wrap_content as both height and width which i do not want.
Any help is greatly appreciated!
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
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
请参阅 http://developer.android.com /guide/topics/resources/drawable-resource.html#LayerList 了解有关如何使用图层列表的更多信息
Try something like this:
See http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList for more information on how to use your layer-list