Problem in drawable canvas to position the text

by Kunal   Last Updated September 13, 2017 13:13 PM

I want to display some text in the bottom right position near my button but its show the text in the left side. How its work? Here is the code!

enter image description here

private void displayInfo(Canvas c) {
    paint.setColor(Color.WHITE);
     paint.setTextSize(scale * 20);

    c.drawText(info, (gWidth - paint.measureText(info)) / 2, (int)(gHeight * 0.10), paint);
     c.drawText(info, (c.getWidth() / 1 - (c.getWidth()/ 1)), (float) (c.getHeight() * .80), paint);
    // c.drawText(info, -.20f, 1000.0f, paint);

     if (decayTime > 0) {
     decayTime--;
     if (decayTime < 1) {
        info = "";
     }
    }


Answers 2


try changing

 c.drawText(info, (c.getWidth() / 1 - (c.getWidth()/ 1)), (float) (c.getHeight() * .80), paint);

to:

c.drawText(info, (c.getWidth() / 1 - (c.getWidth()/ 1))*c.getWidth(), (float) (c.getHeight() * .80), paint);
Jão
Jão
September 13, 2017 12:33 PM

I think you want to draw at x=gWidth - paint.measureText(info) instead of the weird mess you have there right now.

Your current, flawed, approach results in x=0.

Tyyppi_77
Tyyppi_77
September 13, 2017 12:38 PM

Related Questions



Libgdx black rectangles problem

Updated May 13, 2016 08:05 AM


Memory consumption

Updated June 15, 2017 22:13 PM

how can i make android studio multiplayer app

Updated August 15, 2017 10:13 AM