public void draw(Canvas canvas, Context context) { Bitmap buttonBitmap = BitmapHolder.get().getBitmap(image); Matrix matrix = new Matrix(); Point p = MetricsConvertion.pointRelativeToPx(scale); float x = MetricsConvertion.pointRelativeToPx(position.getPoint()).getX(); float y = MetricsConvertion.pointRelativeToPx(position.getPoint()).getY(); float ratio = (float) buttonBitmap.getHeight() / (float) buttonBitmap.getWidth(); // transformations. matrix.postScale( (float) p.getX() / (float) buttonBitmap.getWidth(), ((float) p.getX() * ratio) / (float) buttonBitmap.getHeight()); matrix.postTranslate(x - p.getX() / 2, y - p.getY() / 2); canvas.drawBitmap(buttonBitmap, matrix, null); paint.setTextAlign(Align.CENTER); paint.setColor(Color.WHITE); canvas.drawText(text, x, y, paint); }
public float getY() { return MetricsConvertion.pointRelativeToPx(position.getPoint()).getY(); }