Search code examples
androidactionbarsherlock

Android Layer-list Badge


I followed this article : http://javarticles.com/2015/09/android-icon-badge-example-using-layer-list-drawable.html . My code is almost exactley the same , with a little tweaking in the positioning part.Regardless what i try it never draws above the first layer drawable height.

I am trying to use this on an ActionBarSerlock drawer toggle button(yuh i know ABS is @Deprecated) or also known as hamburger, but how am i to set the circle to draw outside the bounds of the first image?I always get something like this:

enter image description here

I want the circle to draw fully and not be cut by the height of the first image.


Solution

  • I used the LayerDrawable method setLayerInset() .Took me some time to play around , now it looks like this:

    mLayerDrawable.setLayerInset(0, 0, vSeperator, hSeperator, 0);
    mLayerDrawable.setLayerInset(1, 0, 0, 0, vSeperator);
    

    Where the vSeprator/hSeparator are density independent calculated values:

    float density = getResources().getDisplayMetrics().density;
                int vSeperator = (int) (10 * density + 0.5f);
                int hSeperator = (int) (10 * density + 0.5f);
    

    Hint: I'm shifting both images in equal of size but opposite directions