bsguru
bsguru

Reputation: 472

Can't use vector drawable as a a bitmap drawable in android

I am packing a vector drawable in a bitmap drawable and trying to use it as background for a view.This complies successfully but crashes during run time with Resource Not Found exception.

Here is the resource xml files:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_fruit_salad"
    android:tileMode="disabled"
    android:gravity="center">
</bitmap>

Where @drawable/ic_fruit_salad is a vector resource.

The xml for layout:

<android.support.v7.widget.RecyclerView
     android:id="@+id/rv_listofitems"
     android:background="@drawable/background_fruit_salad"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

But if vector resource is used directly it works fine.The reason I am packing in a bitmap is not to stretch the bitmap when used as background for the view.I know there might be some other methods to achieve this , but I am wondering why this doesn't work.

Upvotes: 5

Views: 3580

Answers (1)

A. Latifi
A. Latifi

Reputation: 21

Creating equivalent png files of your vector asset is helpful. Use File->New->Image Asset menu and set your vector drawable address in the path.

Upvotes: 2

Related Questions