Search code examples
androidlayer-list

Custom drawable with Layer-list


I'm going to create a drawable like below image that is included an arrow image.

When I use layer-list , arrow image appear in middle of my drawable!!!

Please let me know how can I achieve it ...

UPDATE: This is my Layer-List:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <shape android:shape="rectangle">
        <corners android:radius="5dp"/>
        <solid android:color="#d5d5d5"/>
        <stroke android:width="1dp" android:color="#242425"/>
    </shape>
</item>

<item android:drawable="@drawable/ic_arrow"></item>


Solution

  • Make a drawable resource file set bitmap as the root element, then set the android:gravity="left" and use this bitmap file as drawable in your layer-list item.

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap
           android:gravity="left"
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:src="@drawable/ic_launcher"/>
    

    layer-list:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
            <item>
               <shape android:shape="rectangle">
    
                     <stroke  android:width="1dp" android:color="@color/blue" />
                    <solid android:color="@color/silver" />
    
                </shape>
           </item>
    
           <item android:drawable="@drawable/stack" />
    
    </layer-list>