我目前图中在代码的自定义视图在画布上的数圈。圆是静态的,不会改变。我想在XML使用ShapeDrawable帮助清理我的代码来吸引他们。我将有许多不同的图形内容,用户可以选择,所以我不希望这样做的代码。具有3个或4的xml可绘看来很多整洁我。

我已创建使用ShapeDrawable在XML一个圆圈但我无法多于一个的形状添加到XML。

如何添加多种形状使用ShapeDrawable XML文档。

有帮助吗?

解决方案 2

我想我已经找到了解决多个形状添加到使用图层列表我的XML文件。 我还没有试过这又但这似乎T为正是我想要的形状将绘制他们的数组索引的顺序。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
      <shape>
         <solid android:color="#FFF8F8F8" />
      </shape>
   </item>
   <item android:top="23px">
      <shape>
         <solid android:color="#FFE7E7E8" />
      </shape>
   </item>
</layer-list>

博客帖子

的Android文档

其他提示

下面是如何做了与一个像素的黑色边框填充红色圆圈,在中间为白色数72:

创建在res \可绘制的XML文件,并适当地命名,例如red_circle_black_border.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid android:color="@android:color/black" />
        </shape>
    </item>
    <item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
        <shape android:shape="oval">
            <solid android:color="@android:color/red" />
        </shape>
    </item>
</layer-list>

然后,使用它在布局,其声明如下:

<TextView
    android:text="72"
    android:textSize="14dp"
    android:textStyle="bold"
    android:background="@drawable/red_circle_black_border" 
    android:layout_width="22dp"
    android:layout_height="22dp"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="@android:color/white" />

显然,根据需要改变TEXTSIZE和layout_width /高度: - )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top