Android:支持同一屏幕尺寸类型内的多种屏幕尺寸

标签 android android-layout

我遇到的问题与支持多种屏幕尺寸有关——我认为这是一个相当普遍的问题。我搜索了很多,但没有找到有用的东西。

我的项目采用传统布局,文件夹支持各种大小,称为 layoutlayout-smalllayout-largelayout-xlarge.

因此,正如我所发现的,即使在这些尺寸范围内,屏幕尺寸也不尽相同。例如,我的 320x480 屏幕符合正常尺寸布局,但其他人的 480x800 屏幕也是如此。可以想象,我的应用程序的内容不会填满 480x800 设备的整个屏幕,因为有更多的区域。以下是它的外观示例:

在 320x480(我设计的)上:

enter image description here

在 480x800 上(注意底部的额外空间):

enter image description here

现在,我做了很多研究并应用了很多技术,努力让我的应用程序在所有屏幕上看起来都不错,但我觉得我缺少一些基本的东西。我已经采取了所有基本步骤来使用 dp 而不是 px,在任何地方都使用 RelativeLayout,诸如此类。但是我需要一些方法让我的应用程序调整自身大小以更好地适应更大的屏幕。例如,各个组件之间的边距可以增加一点,以占据更多的空白垂直空间。

有什么建议或帮助吗?在最坏的情况下,有没有一种方法可以设计一个专门为 480x800 屏幕启动的布局(因为它们似乎最常见)?谢谢。

最佳答案

如果我是你,我会使用这样的布局:

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <!-- Your first form line -->
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <!-- Your second form line -->
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <!-- Your third form line -->
    </LinearLayout>
        <!-- .... -->

</LinearLayout>

这个布局会产生this (当然没有颜色 :) )。线条(彩色框)的比例是固定的,但它的大小动态地适合屏幕高度。 fill_parent 和 layout_weight 可以解决问题。

如果你想使用 RelativeLayout,你必须从 JAVA 编程设置空格和高度(一些解释 here )

关于Android:支持同一屏幕尺寸类型内的多种屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12026816/

相关文章:

android - 如何定位 View 以便点击在动画后起作用

Android Eclipse 程序错误

Android 替代 iOS Google map API GMSGeometryOffset

android - EditText onClick 不显示虚拟键盘

android - 字符串资源新行/n 不可能?

android - 如何根据单选按钮选择填充微调器?

android layout-land 和 onConfigurationChanged

android - 当键盘在 android 中弹出时,无论设备和屏幕分辨率如何,我如何改变我的观点?

android - 如何更改primary和primaryDark颜色?

android - 未定义 layoutweight 属性时 View 消失