2015-07-20 75 views
0

您好,我正在设计一个Android应用程序。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> 

回答

0

设置了滚动的fillViewport属性为 “真”:

<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"> 
0

添加到您的滚动型

android:fillViewport="true" 

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

你的滚动型,更新

<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> 
0

给background属性(机器人:背景= “#ffd4d4d4”)到ScrollView

0

使用以下代码,在滚动视图中填充颜色 <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">