Q:

My Fragment layout is overlapping Activity layout

I have an Activity with two buttons. Button click opens a new Fragment. But the Fragment view is overlapping my Activity view. 
I have tried giving background to my fragment but it is not working for me

Here is activity xml code
<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:background="#E6E6E6"
    tools:context=".TourAdmin">

        <TextView
            android:id="@+id/tour_admin_tour_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="60dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Tournament Name"
            android:textSize="30dp" />

        <Button
            android:id="@+id/tour_admin_schedule"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tour_admin_tour_name"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="50dp"
            android:background="@color/colorPrimary"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Schedule Match"
            android:textColor="#fff" />

        <Button
            android:id="@+id/tour_admin_show_for_score"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tour_admin_schedule"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:background="@color/colorPrimary"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Score Match"
            android:textColor="#fff" />

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

</RelativeLayout>

Here is fragment xml code:
<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:layout_margin="2dp"
    android:background="@android:color/holo_red_dark"
    tools:context=".TourScheduleMatch">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Spinner
                android:id="@+id/tour_team1_select_spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp" />

            <Spinner
                android:id="@+id/tour_team2_select_spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tour_team1_select_spinner"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="40dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                />

            <Spinner
                android:id="@+id/tour_sched_half_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tour_team2_select_spinner"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="40dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:entries="@array/match_time"/>

            <Spinner
                android:id="@+id/tour_sched_nop"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tour_sched_half_time"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="40dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:entries="@array/tournament_nop"/>

            <EditText
                android:id="@+id/tour_cityNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="24dp"
                android:layout_marginTop="24dp"
                android:layout_marginRight="24dp"
                android:layout_weight="0"
                android:hint="City"
                android:inputType="text"
                android:padding="8dp"
                android:layout_below="@id/tour_sched_nop"/>

            <EditText
                android:id="@+id/tour_groundNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="24dp"
                android:layout_marginTop="24dp"
                android:layout_marginRight="24dp"
                android:layout_weight="0"
                android:hint="Ground"
                android:inputType="text"
                android:padding="8dp"
                android:layout_below="@id/tour_cityNameEditText"/>

            <LinearLayout
                android:id="@+id/match_date_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_below="@id/tour_groundNameEditText"
                android:layout_centerHorizontal="true">

                <Button
                    android:id="@+id/tour_match_date_bn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    android:background="@color/colorPrimary"
                    android:paddingLeft="6dp"
                    android:paddingRight="6dp"
                    android:text="Match Date"
                    android:textColor="#fff" />

                <TextView
                    android:id="@+id/tour_match_date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="85dp"
                    android:layout_marginTop="28dp"
                    android:text="Match Date"
                    android:textColor="#000"
                    android:textSize="20dp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/match_time_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/match_date_layout"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp">

                <Button
                    android:id="@+id/tour_match_time_bn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="24dp"
                    android:background="@color/colorPrimary"
                    android:paddingLeft="6dp"
                    android:paddingRight="6dp"
                    android:text="Match Time"
                    android:textColor="#fff" />

                <TextView
                    android:id="@+id/tour_match_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="85dp"
                    android:layout_marginTop="28dp"
                    android:text="Match Time"
                    android:textColor="#000"
                    android:textSize="20dp" />

            </LinearLayout>

            <Button
                android:id="@+id/tour_schedule_schedule_bn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/match_time_layout"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="40dp"
                android:background="@color/colorPrimary"
                android:text="Create"
                android:textColor="#fff" />
        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>

</RelativeLayout>

A:

Using RelativeLayout here is wrong option. You should use LinearLayout instead. Place your FrameLayout as first view in your activity layout and change its visibility from gone to visible when needed.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#E6E6E6"
          android:orientation="vertical">

<FrameLayout
    android:id="@+id/admin_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"/>

<TextView
    android:id="@+id/tour_admin_tour_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="60dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:text="Tournament Name"
    android:textSize="30dp" />

<Button
    android:id="@+id/tour_admin_schedule"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:layout_gravity="center_horizontal"
    android:background="@color/colorPrimary"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:text="Schedule Match"
    android:textColor="#fff" />

<Button
    android:id="@+id/tour_admin_show_for_score"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tour_admin_schedule"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="40dp"
    android:background="@color/colorPrimary"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:text="Score Match"
    android:textColor="#fff" />

</LinearLayout>

Another option is using ConstraintLayout but it is harder to use than LinearLayout.

