Fernando Camargo
Fernando Camargo

Reputation: 3110

Android - How to make a background pattern combining bitmaps?

I know how to make a background pattern repeating a bitmap. I also saw a way to combine two bitmaps using Canvas. But I want to make a repeating bitmap in combination with a gradient drawable to make a background. I have a .png file that it's partially transparent and I want to repeat it along with a gradient drawable (normal gradient XML).

This is the PNG: http://subtlepatterns.com/?p=1203

Is there a way to do this?

Thanks in advance.

Upvotes: 4

Views: 3578

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

You can use an XML bitmap to create a tile pattern:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/my_png"
    android:tileMode="repeat" />

Then you should be able to use this as part of a LayerList drawable that also includes your gradient. Then use the layer list as the background drawable.

Upvotes: 10

Related Questions