Question

I have an application which has a screen with list view. On this list view i am displaying different apps with their image and name in each row(using arraylist). Onclick of an app(in a row) it would launch that particular app. Now when there is an update to any app i want to show a badge on the image of the app. Can this be done?

I have the image stored as a bitmap. Is there any way i can add a badge to a bitmap(not a resource but obtained from web url) or any way to show the badge in a listview with an arraylist.

Was it helpful?

Solution

try this. You may need to amend the size options depending on the size of your image. I use this for 128x128 images.

public static Bitmap getOverlayedImage(Resources res, Drawable img1, Drawable img2) {
  float den = res.getDisplayMetrics().density;
  int dip = (int) (80 * den + 0.5f);
  int sz = (int) (128 * den + 0.5f);

  Drawable[] layers = new Drawable[2];
  layers[0] = img1;
  layers[1] = img2;

  LayerDrawable layerDrawable = new LayerDrawable(layers);
  layerDrawable.setLayerInset(1, dip, dip, 0, 00);

  Bitmap b = Bitmap.createBitmap(sz, sz, Bitmap.Config.ARGB_8888);
  layerDrawable.setBounds(0, 0, sz, sz);
  layerDrawable.draw(new Canvas(b));

  return b;
}

call it like this:

getOverlayedImage(getResources(), drawable1, drawable2);

OTHER TIPS

There's a library that let's you attach a badge: https://github.com/jgilfelt/android-viewbadger

You can add the badge to the ImageView (or any other view you're using) that contains your image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top