Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw triangle shape in android xml [duplicate]

Traingle Image
How to create shape in android using xml? and can we arrange those triangles as circle?

like image 944
Sridhar T Saminathan Avatar asked Jun 21 '17 05:06

Sridhar T Saminathan


1 Answers

Try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/rightArrow">
        <rotate
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%" >
            <shape
                android:shape="rectangle"  >
                <stroke android:color="@android:color/transparent" android:width="10dp"/>
                <solid
                    android:color="#000000"  />
            </shape>
        </rotate>
    </item>
</layer-list>

For the desired direction of triangle you can play with the degrees and pivotx/y points

e.g

<rotate
            android:fromDegrees="220"
            android:toDegrees="0"
            android:pivotX="35%"
            android:pivotY="5%" >
            <shape
                android:shape="rectangle" >
                <stroke android:color="#000000" android:width="1dp"/>
                <solid
                    android:color="#000000" />
            </shape>
        </rotate>

will give you 'v' shaped triangle

alternate for rotate this property also given v shape triangle

android:rotation="180"
like image 135
Ichigo Kurosaki Avatar answered Nov 05 '22 06:11

Ichigo Kurosaki