I want to draw on canvas month's text vertical along screen height.
Paint init:
this.paint = new Paint();
this.paint.setAntiAlias(true);
this.paint.setDither(true);
this.paint.setSubpixelText(true);
this.paint.setColor(color_text_dark);
this.paint.setTextAlign(Align.RIGHT);
Drawing:
// Set the scale to the widest month
float scale = getHeight() / this.max_month_width;
String month_string = FULL_MONTH_NAME_FORMATTER.
format(active_month_calendar.getTime());
canvas.save();
canvas.translate(getWidth(), 0);
canvas.rotate(-90);
canvas.scale(scale, scale);
canvas.drawText(month_string, 0, 0, this.paint);
canvas.restore();
Result looks good on hdpi screen, but very ugly and pixelated on xhdpi one.
I did more test on various devices, and understood what result depends on Android version, not screen density and resolution.
Code works fine on 2.x platform, but doesn't work on 4.0.3+. Suppose, Android draw implementation was changed here.
Full code you can see here.
hdpi version 2.3.5 (also tested 2.2)
xhdpi version 4.2 (also tested 4.1, 4.0.3)
Trying different variations for paint antialias, subpixel text has no effect. How can I fix this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…