Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing triangle in XML [duplicate]

Tags:

android

In XML I'm attempting to draw a drop down triangle to be used as a background for a button but cant seem to get my head round the rotate XML tags.

Here's my XML code:

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="80%"
            android:pivotY="20%">
            <shape
                android:shape="rectangle" >
                <solid
                    android:color="#FFCC00" />
            </shape>
        </rotate>
    </item>
</layer-list>

And here's the outcome of the XML:

enter image description here

Any ideas are appreciated.

like image 871
TokTok123 Avatar asked Dec 20 '22 12:12

TokTok123


2 Answers

i can draw triangle shape using XML triangle .xml

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

            <solid android:color="#00ACED" />
        </shape>
    </rotate>
</item>
</layer-list>

triangle

like image 118
MilapTank Avatar answered Jan 10 '23 06:01

MilapTank


Try out the Below

  <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item >
        <rotate
            android:fromDegrees="-45"
            android:toDegrees="45"
            android:pivotX="90%"
            android:pivotY="-50%" >
            <shape
                android:shape="rectangle"  >
                <stroke android:color="@android:color/transparent" android:width="1dp"/>
                <solid
                    android:color="#ffffff"  />
            </shape>
        </rotate>
    </item>
</layer-list>
like image 29
Biplab Avatar answered Jan 10 '23 06:01

Biplab