简体   繁体   English

Android布局-适用于所有屏幕尺寸的布局吗?

[英]Android layouts - one layout for all screen sizes?

We have a confusion about the best practices of Android layout design. 我们对Android布局设计的最佳做法感到困惑。 Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... ) or for width/height concept (sw, sh etc folder structure). 到目前为止,我们为每种屏幕尺寸(hdpi,XHDPI,xxhdpi ....)或宽度/高度概念(sw,sh等文件夹结构)设计了布局。 Any away we had multiple layout to support multiple screen sizes. 无论如何,我们都有多种布局来支持多种屏幕尺寸。 Sometimes most of they are just a copy of hdpi as Android managed to scale things properly. 有时,它们大多数只是hdpi的副本,因为Android设法正确缩放了东西。

Now we hired a senior Android developer with 5. 5 Years of experience and he prefers to write only one layout to all screen sizes. 现在,我们聘请了一位具有5. 5年经验的高级Android开发人员。他更喜欢只为所有屏幕尺寸编写一种布局。 He argues that this is the latest way. 他认为这是最新的方式。 He only write one layout and when it comes to images he add them to different drawable folders (hdpi drawable folder etc) with different sizes to match across all screens 他只写一种布局,当涉及到图像时,他将它们添加到不同大小的可绘制文件夹(hdpi可绘制文件夹等)中,以在所有屏幕上匹配

At the moment I am also confused thinking whether I really missed an industry standard, because this new guy's past UIs also seems pretty good. 此刻,我也很困惑我是否真的错过了行业标准,因为这个新手过去的UI看起来也不错。

Any advice on this please? 有什么建议吗?

Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... ) 到目前为止,我们为每种屏幕尺寸(hdpi,XHDPI,xxhdpi ....)设计了布局。

Those are not sizes. 那些不是大小。 Those are densities. 这些是密​​度。

or for width/height concept (sw, sh etc folder structure) 或用于宽度/高度概念(SW,SH等文件夹结构)

Those are sizes. 这些是尺寸。

He only write one layout and when it comes to images he add them to drawable folders (hdpi drawable folder etc) with different sizes to match across all screens... whether I really missed an industry standard 他只写一种布局,当涉及到图像时,他将它们添加到具有不同大小的可绘制文件夹(hdpi可绘制文件夹等)中,以在所有屏幕上匹配...是否真的错过了行业标准

Having layouts based upon densities has been a code smell since late 2009, when the concept of screen densities was introduced. 自2009年末引入屏幕密度概念以来,基于密度的布局一直是一种代码味。 Having drawables based upon densities has been a best practice over the same timeframe. 在同一时间范围内,基于密度的可绘制对象是一种最佳做法。

In terms of the "one layout" portion, that may not be practical in all cases: 就“单一布局”部分而言,可能并非在所有情况下都可行:

  • Different orientations (portrait vs. landscape) may require different layouts (eg, to get forms to fit without scrolling) 不同的方向(纵向与横向)可能需要不同的布局(例如,使表格适合而不滚动)

  • Substantially different screen sizes (eg, phones versus tablets) may require different layouts 屏幕尺寸(例如,手机和平板电脑)存在很大差异时,可能需要使用不同的布局

  • Substantially different UI approaches (eg, watches vs. handheld mobile devices vs. TVs) usually require different layouts 实质上不同的UI方法(例如,手表与手持移动设备与电视)通常需要不同的布局

you should fix your height and width of the view in dimension file for various resolution example: 您应该针对各种分辨率示例在尺寸文件中固定视图的高度和宽度:

values folder: 值文件夹:

90dp 75dp 90dp 75dp

values-hdpi folder: values-hdpi文件夹:

    <dimen name="width">100dp</dimen>
    <dimen name="height">85dp</dimen>

like this do for mdpi,,xhdpi,xxhdpi and put this in your view. 像这样对mdpi ,, xhdpi,xxhdpi进行处理,然后将其放入您的视图。

android:layout_width="@dimen/width" android:layout_height="@dimen/height" android:layout_width =“ @ dimen / width” android:layout_height =“ @ dimen / height”

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

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