I simply want to scale 10 characters of text to use the full screen width using textSize alone. If screen resolution is 100 x 100 and I want 10 characters to fully occupy the screen horizontally, why can't I just use:
DisplayMetrics metrics = getResources().getDisplayMetrics();
float pixelFontSize = metrics.widthPixels / 10f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, pixelFontSize);
? In my testing, I get text that is way to small (uses about 1/3 the resolution) on a 280 x 280 wtih 280 dpi AVD, yet on another AVD 360 x 330 hdpi, the code above produce text way too big to fit on one line. ...I mean, sure I could see needing to subtract a small amount from the pixcelFontSize to account for text layout, but my results are all over the place. I must be missing something. First I was messing with density and the scaled measurement dp and sp, but logic would say that given my problem, density has nothing to do with it at all, right?
Aucun commentaire:
Enregistrer un commentaire