【问题标题】:Set width of Android Drawable item?设置Android Drawable项目的宽度?
【发布时间】:2012-04-26 18:20:55
【问题描述】:

我想要的是左边有红色部分的背景。像这样的东西。

我尝试了很多东西(有没有所见即所得的编辑器?我想我运行了数百次。)像下面的文章中那样指定宽度不起作用。 how to specify width and height of a drawable item

下面的文章只告诉我我不能使用百分比,现在如何应用宽度。 Android Drawable: Specifying shape width in percent in the XML file?

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

            <shape>
                <solid 
                android:color="#FFFFFFFF"/>
            </shape>

    </item>
    <item>

            <shape android:shape="rectangle">
                <solid android:color="#55FF0000" />
                <size android:width="100px" />
            </shape>

    </item>

</layer-list>

【问题讨论】:

    标签: android xml-drawable


    【解决方案1】:

    与其指定红色框的大小,不如定义一个红色层,然后将白色层的左边距设置为要显示的红色量。

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <solid android:color="#55FF0000" />
            </shape>
        </item>
        <item android:left="100px">
            <shape android:shape="rectangle">
                <solid android:color="#FFFFFFFF"/>
            </shape>
        </item>
    </layer-list>
    

    如果您知道所需的负空间,您甚至可以交换两者并将红色(现在是顶部)层的右边距设置为应该可见的白色量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2017-02-21
      • 2017-10-27
      相关资源
      最近更新 更多