在给定的截图中如何设置图像而不是关闭文本?

时间:2015-10-28 12:20:40

标签: android paint

  

我无法使用画布设置图片而非关闭文字。关闭   使用以下方法创建文本。

private void drawCenterText(Canvas canvas, Paint paint) {
    paint.setColor(mToggleMenuTextColor);
    switch (mOrientation) {
    case VERTICAL_RIGHT:
        canvas.drawText(openMenuText,
                getWidth() - paint.measureText(openMenuText),
                getHeight() / 2, paint);

        break;
    case VERTICAL_LEFT:
        canvas.drawText(openMenuText, 2, getHeight() / 2, paint);

        break;
    case HORIZONTAL_TOP:
        canvas.drawText(openMenuText,
                (getWidth() / 2) - (paint.measureText(openMenuText) / 2),
                textSize, paint);

        break;
    case HORIZONTAL_BOTTOM:
        canvas.drawText(openMenuText,
                (getWidth() / 2) - (paint.measureText(openMenuText) / 2),
                getHeight() - (textSize), paint);

        break;
    }
}

enter image description here

1 个答案:

答案 0 :(得分:3)

我希望这可以帮助你,我没有尝试过,但它应该让你开始。

 @Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int width = getWidth();
    int height = getHeight();

    int bitWidth = b.getWidth();
    int bitHeight = b.getHeight();

    if (width > 0 && height > 0)
        canvas.drawBitmap(b, (width / 2) - (bitWidth / 2), height - (bitHeight), mPaint);
    else
        canvas.drawBitmap(b, 0, 0, mPaint);
}

其中b是我的位图,其中任何图标都初始化为

 b = BitmapFactory.decodeResource(getResources(), R.drawable.icon);