简体   繁体   English

确保Android布局适合所有设备

[英]Make sure android layout will fit on every device

I have a question about checking layouts on Android. 我有一个关于在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. 我知道有关屏幕尺寸的所有基本知识(尺寸与密度),我通常使用listview或scrollview进行布局,因此无论设备高度如何,它都只会显示或多或少的内容。 Problem is I often have a particular layout to make (from iPhone "render" usually). 问题是我经常要制作一个特殊的布局(通常是从iPhone渲染)。 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. 我必须连续制作3个按钮,所以我制作了LinearLayout,里面有3个按钮,其中layout_width 0dp和layout_weight 1。 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. 我使用Android Studio(最新版本)构建布局,因此可以在不同的屏幕尺寸和密度下看到预览。 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. 但是,我已经将apk发送给了一位朋友,后者向我发送了一个屏幕截图,该屏幕截图显示按钮上的一个字母降到了第二行。 I was using; 我在用;

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

His phone is LG L65. 他的手机是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. 如果您希望按钮是单行的,则可以在按钮上使用android:singleLine="true" 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 ... 如果要单行按钮而不是椭圆形,则必须构建一个自定义视图,以便在需要时缩小文本的大小...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确保每个Android设备中的速度与Android游戏相同? - How to make sure the speed in every android device is same for an android game? 如何使图像适合Android应用程序上的所有设备 - How can I make images fit every device on android application 如何确保 UI 布局适合 Unity 中每个受支持的设备? - How to make sure UI layout fits every individual supported device in Unity? 如何进行布局,使Cardview与每个Android屏幕尺寸的设备兼容? - How to make a layout, with cardviews compatible for every android screen size device? 如何确保Android应用程序可以在每个设备上运行 - How to be sure that Android application will work on every device 如何使图适合Android上的布局 - how to make a graph fit with layout on android 获取布局以适合android中的某些设备屏幕尺寸 - getting a layout to fit some device screen size in android 如何确保android view的布局完整? - How to make sure that android view did full layout? 确保您有一个正在运行的 Android 模拟器或已连接的设备 - Make sure you have an Android emulator running or a device connected and have 如何以编程方式删除视频 android 并确保将其从设备中删除? - How to programmatically delete a video android and make sure it is removed from device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM