1

I am writing an application that consists of a gauge view. I downloaded from here and i want to draw text inside the gauge view (that is at the center of the gauge view) how can i draw a text inside a gauge view please help me.

After my friends answers in stack overflow i did it like this but it did not works please make it work

 private void drawGauge() 
    {
        if (null != mBackground) 
        {
           mBackground.recycle();
        }

        /*--For Semi circle put getHeight()/2--*/
        mBackground = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        newBitmap = Bitmap.createBitmap(mBackground.getWidth(), mBackground.getHeight(), Config.ARGB_8888);
        Canvas newCanvas = new Canvas(newBitmap);
        final Canvas canvas = new Canvas(mBackground);
        final float scale = Math.min(getWidth(), getHeight());
        canvas.scale(scale, scale);
        canvas.translate((scale == getHeight()) ? ((getWidth() - scale) / 2) / scale : 0,(scale == getWidth()) ? ((getHeight() - scale) / 2) / scale : 0);

        Paint paintText = new Paint(Paint.ANTI_ALIAS_FLAG);
        paintText.setColor(Color.WHITE);
        paintText.setTextSize(50);
        paintText.setTextAlign(Align.CENTER);
        paintText.setStyle(Style.FILL);
        Rect rectText = new Rect();
        paintText.getTextBounds(captionString, 0, captionString.length(), rectText);
        newCanvas.drawText(captionString, 0, rectText.height(), paintText);


        //canvas.drawText("MedeQuip", 200, 500, shadowpaint);
        //drawRim(canvas);
        //drawFace(canvas);

For vipluv:

 protected void onDraw(final Canvas canvas) {
        drawBackground(canvas);
        final float scale = Math.min(getWidth(), getHeight());
        canvas.scale(scale, scale);
        canvas.translate((scale == getHeight()) ? ((getWidth() - scale) / 2) / scale : 0, (scale == getWidth()) ? ((getHeight() - scale) / 2) / scale : 0);

        if (mShowNeedle) {
            drawNeedle(canvas);
        }

        if (mShowText) {
            drawText(canvas);
        }

        Paint paintText = new Paint(Paint.ANTI_ALIAS_FLAG);
        paintText.setColor(Color.WHITE);
        paintText.setTextSize(150);
        paintText.setTextAlign(Align.CENTER);
        paintText.setStyle(Style.FILL);
        Rect rectText = new Rect();
        paintText.getTextBounds(captionString, 0, captionString.length(), rectText);
        canvas.drawText(captionString, rectText.width(), rectText.height(), paintText);

        computeCurrentValue();
    }
Laurel
  • 5,965
  • 14
  • 31
  • 57
lakshman
  • 181
  • 8
  • 20

1 Answers1

0

In the onDraw() function in their GaugeView.java file, add a canvas.drawText() just before the call to computeCurrentValue().

Use your own Paint object, and make sure you have initialized its textsize and color properties.

vipluv
  • 607
  • 5
  • 8