简体   繁体   English

Android-如何使用户界面在设备上看起来相同?

[英]Android - How to make UI look same across devices?

There is a variety of devices on the market, with different screen sizes, resolutions and pixel density. 市场上有各种各样的设备,它们具有不同的屏幕尺寸,分辨率和像素密度。

What are some layout preferences or tips/tricks that are generally used to make sure the app looks the same across devices? 通常使用哪些布局偏好设置或提示/技巧来确保应用程序在设备上看起来相同?

Thanks Chris 谢谢克里斯

I always use the "dip" as standart unity instead of pixels, use layout_weight to make proportions 我总是使用“ dip”作为标准单位而不是像素,使用layout_weight进行比例调整

and all my app's are fully compatible to 10 inches tablet devices and small smartphones with 3,2 inches screen! 我所有的应用程序都完全兼容10英寸平板电脑设备和3,2英寸屏幕的小型智能手机!

For a start, you could try positioning and scaling UI elements based of a percentage of the screen (for example, placing a button at 75% of the screen). 首先,您可以尝试根据屏幕的百分比来定位和缩放UI元素(例如,将按钮放置在屏幕的75%处)。 In other circumstances, for example having a window attached to the right of the screen, just get the width of the screen minus the size of the window and place it there. 在其他情况下,例如将一个窗口连接到屏幕的右侧,只需将屏幕的宽度减去窗口的大小,然后将其放置在此处即可。

Make sure you grasp the different between wrap_content and fill_parent on the layouts. 确保掌握布局上wrap_contentfill_parent之间的区别。 In in elements that are arranged vertically (like a list), you will almost always want wrap_content on the height and fill_parent on the width. 在垂直排列的in元素(如列表)中,几乎总是希望将wrap_content放在高度上,将fill_parent放在宽度上。 Vice versa for elements arranged hortizontally. 反之亦然。

As Profete162 said, always prefer the dip unit (it can be thought of as an abstracted pixel size). 正如Profete162所说,总是更喜欢dip单位(可以将其视为抽象的像素大小)。 It helps insure that different resolution-densities don't break your hard-coded widths and heights. 它有助于确保不同的分辨率密度不会破坏您硬编码的宽度和高度。 Ideally, there should never be a mention of dip in your theme code, but what is good in theory is not always pragmatic in practice. 理想情况下,主题代码中永远不要提及dip ,但理论上的优点在实践中并不总是实用的。

These days, you should never use px for the size of something. 如今,您永远不要使用px来表示大小。

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

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