Home » Android » android – adding a image to layerlist item with shape

android – adding a image to layerlist item with shape

Posted by: admin June 15, 2020 Leave a comment

Questions:

i have a xml as below i trying to add a image from drawable folder but its not working.

<solid android:color="#FFF"/> this is where i need to add image from drawable folder

<shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#FFF"/>
        <stroke android:width="1dip" android:color="#225786" />
        <corners android:radius="10dip"/>
        <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
    </shape>

is there any other way that i can add i tried with layer list with item this is how i have tried

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:drawable="@drawable/background">
        <shape>
            <solid/>
            <stroke android:width="1dip" android:color="#225786" />
            <corners android:radius="10dip"/>
            <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
        </shape>
    </item> 
  </layer-list> 

Now its not displaying the border which i am doing with shape it only adds a background to it.

How to&Answers:

If your want a background with border, try this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:drawable="@drawable/background" />
    <item 
        <shape>
            <solid/>
            <stroke android:width="1dip" android:color="#225786" />
            <corners android:radius="10dip"/>
            <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
        </shape>
    </item> 
  </layer-list> 

and if your just want a background, try this one:

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

</bitmap>