我正在尝试创建一个XML drawable,它将在左侧有一个图像,然后是一个纯色背景,它将填充使用该drawable的所有宽度。背景颜色与我在图像本身中使用的颜色相同,目的是在整个宽度上继续使用该颜色。
我已经尝试过了,但这只是给了我应用它的视图中心的图像。我想要的是图像的左侧,然后是图像的右侧,背景色可以填充剩余的剩余空间。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item>
<shape android:shape="rectangle">
<solid android:color="#00355f"/>
</shape>
</item>
<item
android:drawable="@drawable/bg_navbar"
android:gravity="center_vertical|start"/>
</layer-list>
显而易见的解决方案是使用我的背景色制作一个LinearLayout,然后将其拖放到其中,但是由于在我的应用程序中都使用了它,所以我希望能够创建XML可绘制资源。
答案 0 :(得分:1)
尝试以下代码段。希望对您有帮助。
<?xml version="1.0"
encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="90"
android:endColor="#ffffff"
android:startColor="#ffffff"
android:type="linear" />
<stroke android:width="1dp"
android:color="#dddbda" />
<corners android:radius="5dp" />
<padding android:bottom="10dp"
android:left="3dp"
android:right="10dp"
android:top="3dp" />
</shape>
</item>
<item>
<bitmap android:gravity="bottom|left"
android:src="@drawable/drdw" />
</item>
</layer-list>
</item>
</selector>