0

我花了很长时间研究布局问题和屏幕尺寸。我已经阅读了这里的 Android 文档,这很有帮助并且很有意义:http: //developer.android.com/guide/practices/screens_support.html

所以,现在我的应用程序在不同的屏幕尺寸上显示完全相同的尺寸,因为我的所有元素都使用 DIP(密度独立像素)。

但是,我面前有两台设备,一台比另一台大,所以这意味着较大屏幕尺寸(Sensation XE)底部的一些空白空间比稍小屏幕尺寸(Desire Z)上的空间。

阅读 Android 文档,一般的解决方案是为具有不同 DIP 数量的 xlarge、large、normal 和 small 屏幕尺寸创建布局。

这很好,但是我的布局非常复杂(很多自定义视图、很多按钮、3 个文本视图、很多分开的图像,所以它们可以点亮),重新创建这些布局需要做很多工作。

然而,如果它被拉伸,布局就可以了。如果它采用例如 Desire Z 的外观,并且实际上只是拉伸了所有内容以适应更大的屏幕,那会很好,因为在这里拉伸应该不是一个大问题。

我的问题是,有没有办法做到这一点而不必重新创建布局 4 次?是的,我意识到我可以复制粘贴其中的大部分内容,但是仅拉伸我拥有的内容会非常方便。

我在平板设备上进行了测试,它显示良好,但一切都很小,并没有填满屏幕。我在不同的文件夹中有不同大小的图像(从 xhdpi 到 ldpi ),所以选择正确的图像应该不是问题。

谢谢,非常感谢任何帮助。

4

2 回答 2

0

是的,一般来说,您可以在某些小部件上使用 android:layout_width 和/或 android:layout_height 的 fill_parent 来拉伸东西以适应您的布局。您还可以通过为 LinearLayout 中的一系列小部件适当地设置 layout_weight 来按比例缩放。怎么做真的只取决于你想做什么,而且很难抽象地回答。如果你有一个例子和一个关于如何做某事的问题,那可能更容易回答。

下面是一个使用 fill_parent 处理不同屏幕尺寸的 RelativeLayout 示例:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView 
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff880000"
        android:text="Some text" />
    <TextView 
        android:id="@+id/second"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@id/first"
        android:layout_toRightOf="@id/first"
        android:background="#ff008800"
        android:text = "More text" />
    <TextView 
        android:id="@+id/third"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/first"
        android:background="#ff000088"
        android:text="Even more text" />
    <TextView 
        android:id="@+id/fourth"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/third"
        android:background="#ff008888"
        android:text="The last text" />
    </RelativeLayout>
于 2012-03-05T12:36:39.037 回答
0

根据 Android 文档,您可以使用相对布局来满足您的需求。在您的视图中对元素使用相对位置。您可以使用以下属性:

完整的属性列表点击这里

于 2016-10-07T08:56:08.033 回答