adding a image to layerlist item with shape

时间秒杀一切 提交于 2019-12-01 01:02:09

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/14377156/adding-a-image-to-layerlist-item-with-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!