Search code examples
androidshapesribbon

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.


Solution

  • 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