4

I'm new to Android dev and I'm having a hard time trying to do something which seems obvious to me: drawing little images on top of a bigger image.

Let's say that I have a 500x500 image and I want to draw icons at different locations. Icons are png files that I load with:

Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.idIcon1)

My "background image" is a LayerDrawable.

Then, I am totally lost... Do I have to create a canvas ? How to draw on my "background image" my icons at different positions?

Francois
  • 10,352
  • 7
  • 44
  • 79

2 Answers2

5
int positionLeft=0;
int positionTop=0;
Bitmap newBitmap =Bitmap.createBitmap(backgroundBitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
canvas.drawBitmap(backgroundBitmap, positionLeft, positionTop,null);
positionLeft=100;
positionTop=100;         
canvas.drawBitmap(iconBitmap,positionLeft,positionTop,null);
imageView.setImageBitmap(newBitmap);
LuFFy
  • 7,689
  • 10
  • 38
  • 58
Abhra
  • 94
  • 3
  • 7
0

You're making simple things difficult. Just use a layout with android:background attribute, and then add ImageViews dynamically with the necessary bitmaps inside.

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
Vladimir Ivanov
  • 42,109
  • 17
  • 76
  • 102
  • In my case the "background" isn't the background of my View. – Francois Jan 29 '11 at 10:45
  • @Vladimir, And there are other applications like adding a video player icon to a thumbnail bitmap. – C-- Feb 20 '14 at 08:16
  • He wants to draw stuff. Don't assume anything like he wants to create a simple view with images. I came here because I need to draw stuff and not create views. – Johann May 02 '21 at 14:40