简体   繁体   中英

Best way to set text size?

What is the best way to set the text size so it looks the same on all devices? The biggest problem I am having is setting the text size on the buttons so everything fits or isn't too small. I have tried setting the size in the xml, and I have just tried setting it dynamically by getting the screen size and messing with the screen width and height to set the size. I had tested different things on different devices and thought all was well, until I just tried my app on the Galaxy Nexus and half of my words were getting chopped off inside of the button. I made some adjustments and the font is now way too small on tablets.

Using the xml has worked fine for me before, but most of these new 7" tablets use the large layout, so my images and text are really small if I set the height, width, and text size with the xml. Setting the widths and hights dynamically have helped with the buttons and image sizes, but the font still doesn't look quite right.

Is my best bet just to find a happy medium via xml(large, x-large, etc.) or are there other ways?

Have you seen this article: Supporting Multiple Screens ? It says:

you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales the size the same as it does for dp.

The same issue is explained here, Different text size for different hardware

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM