Search code examples
androidandroid-layoutandroid-fragmentsandroid-linearlayout

LinearLayout unexpected margin at the top


I am using a BottomNavigationBar and LinearLayout as the first layout tab but this unexpected margin at the top is showing i already changed my dimens to 0dp but nothing changes.

This is my Main fragment

<LinearLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

    <View
    android:id="@+id/controlView"
    android:layout_width="match_parent"
    android:layout_height="16dp" />

    <FrameLayout
    android:id="@+id/content_frag"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

</FrameLayout>

    <android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/colorPrimaryDark"
    app:menu="@menu/navigation" />

</LinearLayout>

Actually there are two layouts having the same margin problem and this is one of them

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey_300">    

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@drawable/gcover"
    android:id="@+id/relativeLayout">

    <de.hdodenhof.circleimageview.CircleImageView 
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profPhoto"
        android:clickable="true"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:padding="20dp"
        android:src="@drawable/default_prof"
        android:scaleType="centerCrop"
        app:civ_border_color="@color/trans"
        app:civ_border_width="2dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:orientation="vertical">

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/prof_invite"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="2dp"
        android:background="@color/green_300"
        android:drawableLeft="@drawable/icon1"
        android:padding="12dp"
        android:text="invite friends" />


    <android.support.v7.widget.AppCompatButton
        android:id="@+id/prof_conf"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="2dp"
        android:background="@color/ball_D"
        android:drawableLeft="@drawable/icon2"
        android:padding="12dp"
        android:text="settings" />

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/prof_out"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="2dp"
        android:background="@color/colorPrimaryDark"
        android:drawableLeft="@drawable/icon"
        android:padding="12dp"
        android:text="log out" />

</LinearLayout>


Solution

  • <View
        android:id="@+id/controlView"
        android:layout_width="match_parent"
        android:layout_height="16dp" />
    

    This is your problem. Remove this and it will be fine.