安卓多屏设计

标签 android android-layout android-assets android-screen-support

我知道有很多关于在 Android 中设计多屏幕支持的文档。我已经阅读了 Android 指南 here以及一些类似的问题,例如 this

但是,对于如何为我的应用程序实现它,我仍然有些困惑。我计划针对以下设备配置

enter image description here

我认为我需要按如下方式构建项目布局是否正确:

  • 中密度普通屏幕 HVGA 320x480 (160dpi):

    res/layout-mdpi (320 x 480 )
    res/layout-land-mdpi (480 x 320 )
    
  • 高密度普通屏幕 WVGA800 480x800 (x854) (240 dpi)

    res/layout-hdpi (480 x 800)
    res/layout-land-hdpi (800 x 480)
    

但是中密度、大屏幕设备呢?

我也计划同时使用高密度和中密度的绘图集。在这个早期阶段,我主要关心的是为每个布局使用合适的背景图像。例如,为了支持480x800 和 480x854 两种尺寸,我打算简单地使用 ImageView 作为背景,例如:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/bg"
    android:scaleType="center"/>

“bg”可绘制对象将始终为 480x854 并使用:

android:scaleType="center"

我希望这会照顾到这两种屏幕尺寸。因此图像保持其原始外观,但在 480x800 屏幕上居中。我会丢失图像中的一些像素,但只要图像未缩放就可以满足我的需要。

我计划为普通屏幕准备一组 320x480 的资源。

我只是希望我在这里遵循正确的程序,所以我很感谢你们提供的任何信息/提示。提前致谢

最佳答案

根据我的经验,您实际上不需要为小/中/大/等屏幕自定义布局,只要您拥有适合不同密度的可绘制对象即可。如文档所述,Android 将尝试在不同的屏幕尺寸上正确呈现您的布局。

By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes.

“其他情况”仅适用于您确实想在大屏幕上更改布局的情况。

使用 android:scaleType="center" 对我有用,但就像你说的那样,如果它也适合较小的屏幕,它会在较大屏幕上的布局周围留下空白空间。如果您有一个完全自定义的 View ,其中的“小部件”应该放置在正确的位置,并且您不想以编程方式确定缩放比例并将相同的缩放比例应用于您的小部件,这绝对是正确的方法。

关于安卓多屏设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53943540/

相关文章:

android - 编辑文本 : set number of characters programmatically

android - 使用 Android Studio 将 github 项目集成到我的应用程序中

Android:如何通过电话号码获取联系人ID?

java - EditText 在 .getText() 上抛出 NullPointerException

java - fragment 中的 ImageView 未显示

android - 对 AAssetManager_fromJava 的 undefined reference

android - 如何将 Assets 文件转换为 XML 文件

android - 将 Material Design Collection 添加到 Android Studio 的 Asset Studio

python - 在 Android 应用程序中实现 Python 功能

android - 如何防止滚动事件被 PopupWindow 拦截