Jhii
Jhii

Reputation: 137

How to create a rectangle with one side slanted in Android?

How do I create a drawable like this?

shape

Upvotes: 0

Views: 4619

Answers (2)

uttam kumar sharma
uttam kumar sharma

Reputation: 21

Instead of slating the right side, I have slanted the left side, however you can use this logic

***

<!-- Colored rectangle-->
<item>
    <shape android:shape="rectangle">
        <padding android:top="35dp"/>
        <size android:width="200dp"
            android:height="40dp" />
        <solid android:color="#13a89e" />
    </shape>
</item>

<!-- This rectangle for the left side -->
<item
    android:right="200dp"
    android:left="-200dp"
    android:top="-200dp"
    android:bottom="-200dp">
    <rotate android:fromDegrees="-45">
        <shape android:shape="rectangle">
            <padding android:top="-35dp"/>
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>

*** Hope this one helps

Upvotes: 0

matheszabi
matheszabi

Reputation: 624

The search keyword is: "Android how to create custom shapes".

You will find many examples. For example this one.

If you image that shape what you want is a regular rectangle + a triangle you get the result from the link provided, just have to adapt the parameters.

altered image

I hope is helpfully!

Upvotes: 1

Related Questions