I have an ImageView subclass that is supposed to display a logo in the bottom corner of the displayed image. I have this onDraw code to draw the icon on top of the image. It works fine on ICS+ but nothing lower. Does anyone know the reason for this?
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int canvasHeight = canvas.getHeight();
int canvasWidth = canvas.getWidth();
Drawable icon = getResources().getDrawable(R.id.icon);
int width = icon.getIntrinsicWidth();
int height = iconcon.getIntrinsicHeight();
int x = canvasWidth - width - PADDING;
int y = canvasHeight - height - PADDING;
icon.setBounds(x, y, canvasWidth - PADDING, canvasHeight - PADDING);
icon.draw(canvas);
}
you may want to ignore
canvas.getWidth()andcanvas.getHeight()and use the values received inonSizeChanged(int w, int h, int oldw, int oldh)instead, because sometimes they don’t match andcanvas.getWidth()/getHeight()gives strange results.