【问题标题】:Should i keep different dimens file for different screen sizes or different screen densities?我应该为不同的屏幕尺寸或不同的屏幕密度保留不同的尺寸文件吗?
【发布时间】:2017-01-24 18:14:59
【问题描述】:

我正在开发我的第一个 android 应用程序,并希望该应用程序仅在手机和平​​板电脑上以纵向模式运行。我使用 Moto G4 plus (1920x1080, 401 ppi) 开发了该应用,但它在小屏幕设备上看起来有所不同。

我从 android 开发者文档中阅读了许多文档,但仍然不清楚我应该如何为不同的屏幕尺寸提供替代资源。

我的应用在 5.5 英寸和 4 英寸设备上看起来非常不同。 那么我应该为不同的屏幕尺寸(如小、中、大)或不同的密度(如 ldpi、hdpi 等)设置不同的值文件夹吗?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    是的,为了更好的 UI,您需要为不同的屏幕尺寸提供不同的布局 您需要创建多个布局 xml 并将其放入 res 文件夹中,如下所示:

    res/layout/your_layout.xml             (layout for normal screen)
    res/layout-small/your_layout.xml       (layout for small screen)
    res/layout-large/your_layout.xml       (layout for large screen)
    res/layout-xlarge/your_layout.xml      (layout for extra large screen)
    

    同样,你需要有多个图像:

    res/drawable-mdpi/your_icon.png        (image for medium density)
    res/drawable-hdpi/your_icon.png        (image for high density)
    res/drawable-xhdpi/your_icon.png       (image for extra high density)
    res/drawable-xxhdpi/your_icon.png       (image for extra extra high density)
    res/drawable-xxxhdpi/your_icon.png
    

    在以下链接中查找更多详细信息: 官方文档: https://developer.android.com/guide/practices/screens_support.html#support

    教程: http://mrbool.com/how-to-handle-multiple-screen-sizes-in-android/31291 http://www.survivingwithandroid.com/2012/07/how-to-support-multiple-screen-in.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 2015-11-18
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多