Background drawable vector not filling screen

Viewed 1822

I have a problem with a vector drawable which I set as background of my RelativeLayout. It is not filling the screen horizontally.

Here is the code for my RelativeLayout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/my_drawable">

        ...
        some text views etc.
        ...

    </RelativeLayout>

And the vector Drawable my_drawable, if it helps to have it posted:

<vector android:height="24dp" android:viewportHeight="110.0"
    android:viewportWidth="110.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:name="border_path" android:fillColor="@color/color_1" android:fillAlpha="1"
        android:pathData="M105.13,107.51L4.89,107.51A2.38,2.38 99.69,0 1,2.51 105.13L2.51,4.89A2.38,2.38 119.37,0 1,4.89 2.51L105.13,2.51A2.38,2.38 119.37,0 1,107.51 4.89L107.51,105.13A2.38,2.38 99.69,0 1,105.13 107.51z"
        android:strokeAlpha="1" android:strokeColor="@color/color_2" android:strokeWidth="5"/>
</vector>

And the screenshot below. AS you see it doesn't fill the whole width. enter image description here

Any suggestions/solutions highly appreciated!

3 Answers

place image view inside a frame layout

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/sample"
                android:text="Hello World!" />

        </FrameLayout>

    </RelativeLayout>

output

Looks like a source image your generated the vector drawable from contains some padding. Make sure to remove it and regenerate drawable again.

I know this is not the solution I was looking for, but rather than playing with vectors, I simply created a shapes drawable XML. My goal was to achieve shadows, hence I started with importing SVGs, but actually I was able to achieve shadows with layer-list of shapes.

If anyone ever stumbles upon a solution, I'd be curious to know.

Thanks all!

Related