Center a Drawable : Drawable « 2D Graphics « Android






Center a Drawable

  
import android.graphics.drawable.Drawable;

 class Utilities {
  static void centerAround(int x, int y, Drawable d) {
    int w = d.getIntrinsicWidth();
    int h = d.getIntrinsicHeight();
    int left = x - w / 2;
    int top = y - h / 2;
    int right = left + w;
    int bottom = top + h;
    d.setBounds(left, top, right, bottom);
  }

}

   
    
  








Related examples in the same category

1.Animate Drawables
2.ShapeDrawable Demo
3.Using GradientDrawable
4.Gets the image drawable from the url
5.Drawable.createFromStream
6.Drawable Manager
7.get Drawable From Url
8.simply resizes a given drawable resource to the given width and height
9.Drawable.createFromStream and URL connection
10.Drawable Manager with Thread
11.get Drawable From Web Operation
12.Rotate around Center Point