0

我在使用相对布局和背景时遇到问题。虽然我设置android:layout_height="match_parent"了,但背景并没有填满整个屏幕(屏幕高度),并且底部设置为白色。我只是将项目放在屏幕的顶部,但即便如此我也不相信这种行为是正确的。

我的代码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:background="@drawable/background" >


<TextView
    android:id="@+id/title"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/title"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/dim_b"
    android:layout_marginLeft="@dimen/dim_a"
    android:layout_marginRight="@dimen/dim_a" />

<EditText 
    android:id="@+id/insert"
    android:hint="@string/insert"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/dim_c"
    android:layout_marginLeft="@dimen/dim_a"
    android:layout_marginRight="@dimen/dim_a"
    android:inputType="textPassword" />

<Button 
    android:id="@+id/accept"
    android:text="@string/accept"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/insert"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/dim_d"
    android:layout_marginLeft="@dimen/dim_a"
    android:layout_marginRight="@dimen/dim_a" />

</RelativeLayout>
4

2 回答 2

2

1.首先您使用的是相对布局,所以为什么需要从相对布局顶部删除orientation="vertical"

2.Edittext ,Button 像这样 android:layout_below="@+id/title" 不是 android:layout_below="@id/title"

于 2012-12-12T18:08:42.923 回答
0

尝试: android:layout_height="fill_parent"

match_parent 处于 API 级别 8 及更高级别。

于 2012-12-12T18:00:19.507 回答