Center a Drawable : Drawable « 2D Graphics « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » 2D Graphics » Drawable 
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.