java - Strange Text Placement on Android 5.0 Lollipop due to android.graphics.Paint.getTextSize() -


here few images reference in post: http://imgur.com/a/rsd57.

right now, following "android game programming dummies" book develop simple 'whack mole' android app, , encountered strange error. when run app on emulator running android 2.1, text indicates number of moles "whacked" , number of moles "missed" placed correctly (first image).

however, when run app on phone (a samsung galaxy s5 active running android 5.0), bottommost pixel of text appears @ top of screen (second image).

i think root of problem here:

    private void draw (canvas canvas) {         try {             canvas.drawbitmap(backgroundimg, 0, 0, null);             if(!ontitle) {                 canvas.drawtext("whacked: " + integer.tostring(moleswhacked), 10, blackpaint.gettextsize()+10,                          blackpaint);                 canvas.drawtext("missed: " + integer.tostring(molesmissed), screenw - (int)(200*drawscalew),                          blackpaint.gettextsize()+10, blackpaint); 

here link source code:

whackamoleview.java: http://pastebin.com/ymmw2cub

i have tried debugging y position of text system.out.println statements, , have found adding "gettextsize()" "10" returns "nan." since gettextsize() returns float, have tried converting 10 float typing "10.0f," addition still returns "nan." strangely, if change y position of "whack" text to:

canvas.drawtext("whacked: " + integer.tostring(moleswhacked), 10, (float)(blackpaint.gettextsize()+10.0),                          blackpaint); 

the "whack" text starts displaying (third image), if change both "whack" , "miss" texts:

canvas.drawtext("whacked: " + integer.tostring(moleswhacked), 10, (float)(blackpaint.gettextsize()+10.0),                          blackpaint);  canvas.drawtext("missed: " + integer.tostring(molesmissed), screenw - (int)(200*drawscalew),                          (float)(blackpaint.gettextsize()+10.0), blackpaint); 

both texts disappear once again (fourth image).

my question is: going on, , how can fix it?

i know lot of code, highly appreciate suggestions!

edit:

i ran on emulator running android 5.1.1, , text placement correct. beginning think result of hardware acceleration optimizations...


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -