简体   繁体   中英

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>

在此处输入图片说明

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 -

在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM