john seymour
john seymour

Reputation: 213

How to set drawable as bitmap in android?

I'm trying to set a repeating image on top of my shape drawable but I'm having trouble with it out. I realize this question has been asked numerous times but I'm still trying to figure out the first step!

I'm new to android so I'm still learning things.

I have managed to set one little icon in the top left but that's obviously not going to do, with this code here -

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


  <item android:drawable="@drawable/gradient_main"/>

  <item android:drawable="@drawable/ic_asset_4"
        android:tileMode="repeat"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp"
        android:bottom="5dp"
        android:gravity="top|left"/>

</layer-list>

enter image description here

I've checked out questions on here already and they all show this

<bitmap android:src="@drawable/example">

Now when I do this the preview comes up with this -

enter image description here

So, I figure I'm missing a step here. The icon I want to repeat on my background is an SVG image I have created in photoshop and then added via the new vector image asset in the drawable folder.

Upvotes: 1

Views: 907

Answers (1)

Viraj Patel
Viraj Patel

Reputation: 2393

Vector Drawable is not allowed as the source for a bitmap drawable.

You can check the issue posted in google's issuetracker here.

So you have to use .png, .jpeg or .jpg file instead of vector icon to display repeat image in your layout.

Upvotes: 1

Related Questions