如何为RelativeLayout边框添加背景颜色?

时间:2017-10-31 15:14:30

标签: android android-layout background android-relativelayout

我想向我的background color #df0031显示RelativeLayout borders,以便我的整个Android screenbackground #df0031包含现在有白色的边框。

Android Screen

请参阅上面的屏幕截图,并以这种方式帮助我更新XML,以便Android Screen的边框与屏幕的其余部分匹配background color #df0031而不是#ffffff

布局(XML):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.sitemakers.sitemakers.HomeFragment"
android:background="@color/colorBgHome"
>

<TextView
    android:id="@+id/home_heading"
    android:layout_marginTop="10dp"
    android:text="WE CREATE AWESOME WEB SITES"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorTextHome"
    />
<TextView
    android:layout_below="@+id/home_heading"
    android:id="@+id/home_text"
    android:layout_marginTop="28dp"
    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut 
    enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
    aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit 
    in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorTextHome"
    />
    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/main_device_image"
    android:textColor="@color/colorTextHome"
    />
</FrameLayout>

Colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorBgHome">#df0031</color>
    <color name="colorTextHome">#ffffff</color>
</resources>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.sitemakers.sitemakers.MainActivity"
tools:showIn="@layout/app_bar_main">

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

感谢您的时间。

4 个答案:

答案 0 :(得分:1)

在片段的容器中,您有填充。只需将其删除即可。

答案 1 :(得分:1)

编辑content_main文件以删除导致白色边框的填充。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.sitemakers.sitemakers.MainActivity"
tools:showIn="@layout/app_bar_main">

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

答案 2 :(得分:1)

你必须删除填充!删除这些行:

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

答案 3 :(得分:0)

从content_main.xml中删除这些行:

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"