Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 395
Fernando Camargo Avatar asked Dec 27 '22 23:12

Fernando Camargo


1 Answers

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.

like image 92
Ted Hopp Avatar answered Jan 13 '23 10:01

Ted Hopp