Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set size of Layered Drawable?

I am making a icon for my app.. The app is basically a friend finder. I am creating a overlay that looks much like the icons from Google Latitude. I have an image that changes due to the user and I have the boarder. I've been able to do the layered drawable and overlay fine, but the problem is, the image stretches to the size of the border. This is a problem because, if you've never seen the Google Lat icons, it has a point on the bottom with open space between it.

What I need to do is, somehow restrict the size of the changing image to the bounds of the square portion of the border. Any Help would be much appreciated. Here is my snippet:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 25;  
    Bitmap bit = BitmapFactory.decodeFile(photo, options);
    draw = new BitmapDrawable(bit);

    Resources r = getResources();
    Drawable[] layers = new Drawable[2];
    layers[0] = draw;
    layers[1] = r.getDrawable(R.drawable.border);
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    draw = layerDrawable;

    }else{
    draw = this.getResources().getDrawable(R.drawable.androidmarker);
    }

    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(draw, this);

    GeoPoint point = new GeoPoint(lat,lon);
    OverlayItem overlayitem = new OverlayItem(point, username, avail + " : " + status + " : Position updated at : " + update_at);
    items.add(overlayitem);
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
like image 707
ninnemannk Avatar asked Feb 25 '11 15:02

ninnemannk


1 Answers

Funny that shorty after I posted this, I found the answer. I was looking in all of the wrong places to resize the image. I tried the bitmap, the drawable, the layers inside of the layerdrawable. But, what I never tried was the layerdrawable itself. The solution is below:

  Resources r = getResources();
    Drawable[] layers = new Drawable[2];
    layers[0] = draw;
    layers[1] = r.getDrawable(R.drawable.border);
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(0, 0, 0, 0, 12);
    draw = layerDrawable;

The layerDrawable inset method is as follows:

layerDrawable.setLayerInset(*index of layer*, *left inset*, *top*, *right*, *bottom*);

Thanks guys!

like image 91
ninnemannk Avatar answered Oct 19 '22 11:10

ninnemannk