Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Draw a ribbon shape

I am trying not to use image view. This is because, later, I will generate many objects with the same shape but different colors, so I wouldn't need to keep adding image views but simply adding colors on my code.

enter image description here

How can I create those images on Android Studio? I looked over Paint, onDraw, Canvas, etc, but this looks difficult to me.

like image 201
SungJin Kim Avatar asked Jul 03 '17 05:07

SungJin Kim


2 Answers

If you want to use from XML , Try this way it will work

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item>
        <shape android:shape="rectangle">
            <size
                android:width="100dp"
                android:height="40dp" />
            <solid android:color="#5EB888" />
            <corners android:radius="0dp"/>
        </shape>
    </item>


    <item
        android:top="-26dp"
        android:bottom="31dp"
        android:left="-90dp"
        android:right="75dp">
        <rotate
            android:fromDegrees="45">
            <shape android:shape="rectangle">
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>



</layer-list>

OUTPUT

enter image description here

like image 111
Aditya Vyas-Lakhan Avatar answered Sep 29 '22 23:09

Aditya Vyas-Lakhan


You can create vector image using any vector program like Adobe Illustrator or convert it using a conversion tool like vectormagic or find already existing one then import it to android studio.

enter image description here

it will be imported as xml file where you can change the colors as you want

like image 26
humazed Avatar answered Sep 30 '22 00:09

humazed