How to take the margins of the Android layout

Asked

Viewed 1,521 times

0

I want to remove those marginsazul for my line verde catch the layout and not be left with any margin, but without removing the padding of RelativeLayout

It is the Actionbar vermelho who is with a margim bottom or my View verde who is with a margin top?

Imagem

xml layout.

<RelativeLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Home">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#ACD10A"
        />
</RelativeLayout>
  • Exception, in general to ActionBar does not interfere with the content layout. Because it modifies its layout to take the View from within the RelativeLayout, encompassing in a LinearLayout?

  • @Wakim can give an example?

1 answer

0


To take the effect of the View which gives the line effect I suggest to encompass its layout in a LinearLayout and put the RelativeLayout below the View. Thus:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Home">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:background="#ACD10A" />

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="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">

        <!-- Restante do layout -->

    </RelativeLayout>
</LinearLayout>

Some considerations:

  1. The use of layout_height="0dp" and layout_weight="1" force that the RelativeLayout occupy all the remaining space, the View that emulates a line will occupy 1dp and the RelativeLayout the rest.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.