创建带圆角的三角形

时间:2016-10-04 13:11:19

标签: android draw shape

我需要创建带圆角的三角形。这是我的代码

<item android:gravity="center">
    <rotate
        android:fromDegrees="45"
        android:pivotX="-40%"
        android:pivotY="87%"
        android:toDegrees="45" >
        <shape android:shape="rectangle" >
            <corners android:radius="2dp"/>
            <solid android:color="#ffffff" >
            </solid>

            <stroke
                android:color="#ffffff" />

        </shape>

    </rotate>
</item>

我的代码只有三角形的一边是圆角的,另外两个角没有圆角。请帮我创建圆角的三角形。

1 个答案:

答案 0 :(得分:4)

enter image description here

triangle.xml创建为res/drawable

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:height="50dp"
        android:width="50dp"
        android:viewportHeight="16.0"
        android:viewportWidth="16.0" >
    <path android:fillColor="@color/colorAccent" 
          android:pathData="M11.844,9.04L8.345,5.163c-0.195,-0.217 -0.511,-0.217 -0.705,0l-0.012,0.02L4.136,9.04c-0.195,0.217 -0.195,0.569 0,0.786l0.006,0.005C4.233,9.936 4.358,10 4.499,10h6.983c0.143,0 0.27,-0.068 0.359,-0.176l0.002,0.002C12.039,9.609 12.039,9.257 11.844,9.04z"/>
</vector>

通过更改android:fillColor

来更改三角形的颜色

并使用@drawable/triangle

这很简单.... 因为简单的drawable没有先进的形状修改功能。