在android

时间:2016-10-03 10:03:01

标签: android matrix

我想将矩阵应用于文本视图。我可以在onDraw方法

上应用矩阵
@Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPaint(paint);
        paint.setColor(Color.BLACK);
        paint.setTextSize(20);

       //transform is the matrix
        canvas.drawBitmap(textAsBitmap("0ps", 26, Color.RED), transform, paint);

    }


    public Bitmap textAsBitmap(String text, float textSize, int textColor) {
        Paint paint = new Paint(ANTI_ALIAS_FLAG);
        paint.setTextSize(textSize);
        paint.setColor(textColor);
        paint.setTextAlign(Paint.Align.LEFT);
        float baseline = -paint.ascent(); // ascent() is negative
        int width = (int) (paint.measureText(text) + 0.5f); // round
        int height = (int) (baseline + paint.descent() + 0.5f);
        Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(image);
        canvas.drawText(text, 0, baseline, paint);
        return image;
    }

但问题是,如果翻译大于视图维度,那么就无法看到翻译。如果视图具有matchparent维,那么就没有问题,它可以正常工作。

enter image description here

如果翻译在白色屏幕上更大,则无法看到它

0 个答案:

没有答案