I have a grid of 18 buttons, apparently this is too big as my text is getting messed开发者_Go百科 up between different res/densities.
50sp looks right on 240 hdpi WVGA800, 30sp looks right on 120 ldpi QVGA and 160 mdpi HVGA. How can I adjust the sizes based on whatever screen is being used?
I'm 99.9% sure you can do it with different xml layouts... but if you're doing it programmatically you would do something like this:
DisplayMetrics dMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
//then run a switch
switch(dMetrics.densityDpi){
case DisplayMetrics.DENSITY_XHIGH:
//set text size
break;
case DisplayMetrics.DENSITY_HIGH:
//set text size
break;
case DisplayMetrics.DENSITY_MEDIUM:
//set text size
break;
case DisplayMetrics.DENSITY_LOW:
//set text size
break;
}
精彩评论