如何用一些指针边缘绘制椭圆形

时间:2014-10-05 02:41:24

标签: android android-shape

我想绘制一些椭圆形的东西,并指向一些东西。如何通过Android中的形状实现它?

enter image description here

1 个答案:

答案 0 :(得分:0)

如果我要做这样的事情,我会使用IDE提供的9patch绘图工具。但是,在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="100dp"
            android:height="100dp" />
        <solid android:color="#5EB888" />
        <corners android:radius="0dp"/>
    </shape>
</item>
<!-- default color for item at the top 5EB888 --> 
<item
    android:top="-40dp"
    android:bottom="65dp"
    android:right="-30dp">
    <rotate
        android:fromDegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>

<item
    android:top="65dp"
    android:bottom="-40dp"
    android:right="-30dp">
    <rotate
        android:fromDegrees="-45">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>

</layer-list>

只需将此drawable作为背景应用于窗口小部件,您将获得一个尖头矩形。在你的情况下,你需要一个椭圆形。您可以根据自己的喜好切换形状并调整尺寸。希望这可以帮助。 将此代码应用于按钮小部件后,您获得的结果如下所示: pointed shape

更多关于ListLayer xml元素here