Namita
Namita

Reputation: 75

One side angled rectangle in android xml

Is there any way to draw one sided angled rectangle in android xml. Like this image below...

enter image description here

Upvotes: 2

Views: 2203

Answers (1)

JiTHiN
JiTHiN

Reputation: 6588

Can be achieved using the following xml code. only downside is that the second rectangle should match the color of background.

 <?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <!-- Colored rectangle-->
        <item>
            <shape android:shape="rectangle">
                <size
                    android:width="100dp"
                    android:height="40dp" />
                <solid android:color="#F00" />
            </shape>
        </item>

<!-- Overlay with same color as background-->
    <item
        android:top="20dp"
        android:bottom="-40dp"
        android:right="-30dp">
        <rotate
            android:fromDegrees="-60">
            <shape android:shape="rectangle">
                <solid android:color="#FFF" />
            </shape>
        </rotate>
    </item>
</layer-list>

Upvotes: 3

Related Questions