有没有办法指定宽度和& xml中`ShapeDrawable`的高度?

时间:2013-07-11 19:05:13

标签: android-drawable shapedrawable layer-list

Android:有没有办法指定宽度&amp; xml中ShapeDrawable的高度?这看起来非常困难。使用<size>子项不起作用,也不会将<shape>包装在图层列表项中并设置android:heightandroid:weight属性。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- 
How do you set shape size?
The top/bottom attributes allow setting size via an inset
from the parent element, but isn't there way to explicitly
set width and height???
-->
    <item
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">
        <shape android:shape="rectangle" >
            <solid android:color="#f00" />
            <stroke
                android:width="1dp"
                android:color="#0f0" />
        </shape>
    </item>

</layer-list>

1 个答案:

答案 0 :(得分:0)

sizepadding标记始终位于shape标记下。请重新检查您的代码。

<item>
    <shape android:shape="rectangle">
        <solid android:color="#FFFFFF" />
        <size android:height="4dp" android:width="15dp" />
        <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
    </shape>
</item>