Issue
I'm trying to create an XML drawable which will have an image on the left, and then a solid background which will fill the rest of the width where ever the drawable is used. The background color is the same color I have in the image itself, and the purpose is to continue the color for the full width.
I've tried this, but this just gives me the image in the center of the View which I apply it to. What I want is the image on the left, and then to the right of the image the background color to fill whatever remaining space is left.
<?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>
The obvious solution is to make a LinearLayout with my background color and then drop the image into it, but since this is used throughout my app, I was hoping to be able to create an XML drawable resource instead.
Solution
Try the below code snippet. I hope it will help you.
<?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>
Answered By - Vishal Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.