Android将背景颜色填充到整个高度

时间:2015-07-20 10:18:21

标签: android xml android-layout

您好我正在尝试设计一款Android应用。

我为我的活动添加了背景颜色。我的问题是如果只有内容,背景颜色会填满整个屏幕。目前它看起来像这样。

enter image description here

只有一半的页面填充了背景色。

有人可以帮助我用完整的颜色填充背景。

这是我的xml代码。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="lk.agent.certislanka.certisagenttracking.ForgotPassword"
    android:background="#ffd4d4d4">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/forgot_password"
        android:id="@+id/txt_v_forgot_password"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="64dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:singleLine="true"
        android:hint="Enter Email Address"
        android:ems="10"
        android:id="@+id/et_email"
        android:layout_below="@+id/txt_v_forgot_password"
        android:layout_alignParentStart="true"
        android:layout_marginTop="33dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Submit"
        android:id="@+id/btn_reset_password"
        android:background="#F89B22"
        android:layout_below="@+id/et_email"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="22dp" />

</RelativeLayout>
</ScrollView>

4 个答案:

答案 0 :(得分:0)

将此内容添加到ScrollView

android:fillViewport="true"

此问题是您的布局没有足够的内容来填充视口。所以只有屏幕的那么多部分才有布局。因此,如果你添加 android:fillViewport =“true”,那么即使没有足够的内容,ScrollView也会填充Viewport。

您的ScrollView,已更新

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:fillViewport="true" >

....
....

</ScrollView>

答案 1 :(得分:0)

将ScrollView的fillViewport属性设置为&#34; true&#34;:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

答案 2 :(得分:0)

将背景属性( android:background =“#ffd4d4d4”)提供给 ScrollView

答案 3 :(得分:0)

使用以下代码,在scrollview中填充颜色     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffd4d4d4">

相关问题