简体   繁体   中英

Make sure android layout will fit on every device

I have a question about checking layouts on Android. I know all basics about screen sizes (size vs density), I usually make layouts with listview or scrollview, so no matter height of device it'll just show more or less content. Problem is I often have a particular layout to make (from iPhone "render" usually). Let's take an example:

I had to made 3 buttons in one row, so I've made LinearLayout with 3 buttons inside, which has layout_width 0dp and layout_weight 1. That did the work. Or it seemed to. I use Android Studio (latest version) to build my layouts, so I can see a preview on different screen sizes and densities. I used "Preview all screen sizes" as well I've looked into "Generic phones and tablets". All were good. However I've sent my apk to a friend, which send me a screenshot that showed one letter from buttons went down to a second line. I was using;

android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"

His phone is LG L65. I had to make font size smaller, because it appeared really big and didn't fit. How can this be even smallest densities were all good and on this phone wasn't? How can I be sure any layout will fit? Isn't using built-in font sizes a good idea? So I have to own a lot of devices and make different font sizes, margins etc for all combinations of screen sizes and densities?

You have to take in account that the font size can be bigger than expected by a system settings. If you want your button to be single lined, you can use android:singleLine="true" on your button. This might ellipsized the text if needed.

If you want single lined button without ellipsized, you have to build a custom view that down scale the text when needed ...

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