代码之家  ›  专栏  ›  技术社区  ›  Kadiem Alqazzaz

如何设计一个可以在多个屏幕上工作的UI?

  •  -1
  • Kadiem Alqazzaz  · 技术社区  · 7 年前

    所以我有两部手机,注3(5.7in 1080p),这里是应用程序的屏幕截图: enter image description here

    我还有A7 2018(6in 1080x2220 18.5:9),这里是截图: enter image description here

    在看到了巨大的差异之后,我如何在多屏幕大小和分辨率上制作稳定的用户界面,更糟糕的是Android Studio的预览缺乏精确性。

    有没有办法为单独的显示类创建类似于单独的XML布局的东西?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Rene Ferrari    7 年前

    这个 link from the official docs 会帮助你的。

    支持不同屏幕大小的方法有:

    • 避免使用绝对值
    • 如果使用绝对值,请使用 dp 尺寸和 sp 字体大小
    • 使用 match_parent wrap_content 如果可能的话
    • 如果你使用 ConstraintLayout Guidelines 可能是你的朋友(可以创建他们的百分比)
    • 如果上面没有任何帮助,请为不同的屏幕大小创建单独的布局。( explained here )
        2
  •  1
  •   Steve Moretz    7 年前

    它既可以使用带有指导原则的ConstraintLayout,也可以针对不同的屏幕大小使用不同的布局。例如,您可以通过在目录中创建文件的不同版本,为手机和平板电脑创建名为“主活动”的布局,如下所示:

    res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
    res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
    

    以下是其他最小宽度值与典型屏幕尺寸对应的方式:

    320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
    480dp: a large phone screen ~5" (480x800 mdpi).
    600dp: a 7” tablet (600x1024 mdpi).
    720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
    

    enter image description here

    查看文档: https://developer.android.com/guide/practices/screens_support#DeclaringTabletLayouts