Android Custom Custom Borders

I am writing a custom Drawable, text above a bitmap:

@Override
public void draw(Canvas canvas) {
    canvas.drawBitmap(badge, matrix, null); 
    canvas.drawText(count, size / 2, size / 2 + (text_size) / 2 , p);
}

When I use my drawable in imageView, everything is fine. good

But if I use this with a text view (composite drawing), this alignment is wrong. wrong

I tried both setCompoundDrawablesWithIntrinsicBounds and setCompoundDrawables

The same results that I missed?

Thank.

+3
source share
1 answer

I manage to get the correct alignment (my drawable is circle / square, so width = height):

In my Custom_Drawable ctor:

Custom_Drawable(int size) {
    this.size = size;
}

onDraw method:

@Override
public void draw(Canvas canvas) {
    // draw here
    setBounds(0, 0, this.size, this.size);
}

When configuring drawable:

 b.setCompoundDrawables(new Custom_Drawable(25), null, null, null);
+4
source

All Articles