【问题标题】:Android Shape - Square with Circle and Different Top ColorAndroid 形状 - 带圆形和不同顶部颜色的正方形
【发布时间】:2015-10-23 08:56:59
【问题描述】:

我正在尝试创建一个 可绘制形状,如下所示。

只有左上角部分是不同的颜色(这里是白色)。以为放置一个较小尺寸的矩形可以让我实现这一点,但我错了。我是否朝着正确的方向前进?

这是我的 drawable.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <size android:width="15dp" android:height="15dp"/>
        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <solid android:color="@android:color/black" />
    </shape>
</item>
</layer-list>

【问题讨论】:

  • 创建一个自定义的Shape 类并将其传递给ShapeDrawable 构造函数

标签: android xml-drawable shapedrawable


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <size android:width="60dp" android:height="60dp"/>
            <solid android:color="@android:color/white" />
        </shape>
    </item>



    <item android:left="40dp">
        <shape android:shape="rectangle">
            <size android:width="30dp" android:height="30dp"/>
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item android:top="30dp" android:bottom="0dip">
        <shape android:shape="rectangle">
            <size android:width="10dp" android:height="10dp"/>
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item>
    <shape android:shape="oval">
        <stroke android:color="@android:color/black" android:width="1dp"/>
        <size android:width="60dp" android:height="60dp"/>
        <solid android:color="#ff0000" />
    </shape>
</item>

</layer-list>

【讨论】:

  • 哇!那是快速而完美的。非常感谢。
  • 如果我的尺寸不同意味着它不适合我吗? 60dp,40dp,30dp,10dp 之类的逻辑是什么?
  • 那么你必须以编程方式创建它
  • 嗨,你能告诉我如何减小圆圈的大小吗?
猜你喜欢
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
相关资源
最近更新 更多