1

我是android开发的新手。我正在为我的 android 应用程序制作 UI。现在,mdpi 屏幕的高度是 480px。所以我将我的 UI 设计为在 mdpi 的屏幕上具有 480px 的高度。但是因为状态栏在设备顶部占用了一些空间,所以我在 RelativeLayout 中的一些 ImageView 是重叠的。如何补偿状态栏占用的空间?因为对于不同的屏幕,状态栏的大小会有所不同,而在平板电脑中,状态栏甚至可能不在顶部。我很困惑,求助!

编辑: XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@android:style/Theme.Black.NoTitleBar" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:clickable="false"
        android:contentDescription="@string/p"
        android:scaleType="center"
        android:src="@drawable/volbar" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:clickable="false"
        android:contentDescription="@string/p"
        android:scaleType="center"
        android:src="@drawable/base" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:contentDescription="@string/p"
        android:scaleType="center"
        android:src="@drawable/head" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="33dp"
        android:layout_marginRight="19dp"
        android:text="@string/press_to_update" />

    <ImageView
        android:id="@+id/imageView9"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView2"
        android:clickable="false"
        android:contentDescription="@string/p"
        android:scaleType="center"
        android:src="@drawable/frag1"
         />

</RelativeLayout>
4

4 回答 4

2

在 Relativelayout 中,您使用了 match_parent / wrap_content。所以它会适合屏幕。但是你已经指定你在 mdpi 的屏幕上设计了 480px 的 ui。由于尚不清楚您如何在 mdpi 屏幕上将 ui 设计为 480px。我猜,可能使用了 Image View 中使用的可绘制对象,它适合 mdpi 屏幕的 480 像素。drawables应该以3:4:6:8的比例放置

例如

lpdi:mdpi:hdpi:xhdpi = 3:4:6:8

例如,如果您将 mdpi 的图像保留为 40px 那么,对于 ldpi = 30 px,hdpi = 60px,xhdpi = 80px。

于 2013-04-13T07:25:14.433 回答
0

As other users suggested, you should not hard code the specific heights but use wrap_content or match_parent.

If you still want to follow this way, why don't you reduce the height of your RelativeLayout by the dimension of the ActionBar? In Android 4.0+ the default height is 48dip, in landscape is 40dp, in sw600dp is 56dp. You can also get height programmatically calling getActionBar().getHeight() in your activity. For more infos about ActionBar appearance, see this link.

于 2013-04-13T09:41:44.643 回答
0

根据Supporting Multiple Screens Best Practices,您应该设计布局以扩展或收缩以填充可用空间。在手机上,最重要的部分是确保您的内容水平适合并且(如果需要)垂直滚动。如果您需要在布局中容纳比设备空间更多的垂直内容,则可以添加ScrollView 。

于 2013-04-13T06:36:36.070 回答
0

不要尝试将高度设置为特定大小。尽可能使用“wrap_content”或“match_parent”作为“layout_height”的值。

如果您觉得内容会高于可用的屏幕高度,您将希望使用 ScrollView 作为内容的容器。

如果您觉得内容总是适合可用的屏幕高度,那么您可以简单地使用带有 layout_height="match_parent" 的容器(如 RelativeLayout)。

如果您有特定的布局需要帮助,您可以发布 XML。

于 2013-04-13T06:37:37.373 回答