title: Fragment coming below the container screen
body: <p>I am trying to add a fragment above an activity. I am adding the fragment on the main container, but instead of ovrlapping the Activity screen, the fragment is coming below the layout of the mainActivity. I know its a very silly question to ask but was unable to find a solution. Below I am posting my code. Need your suggestions.</p>
  
  <pre><code>MainActivity.java:
  
      public class MainActivity extends AppCompatActivity {
      private FirebaseAuth mAuth;
      private FirebaseAuth.AuthStateListener mAuthListener;
  EditText email, password;
      TextView login,signup;
  
      public FragmentManager fragmentManager;
      public FragmentTransaction fragmentTransaction;
      Fragment fragment;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mAuth = FirebaseAuth.getInstance();
  
          email = (EditText) findViewById(R.id.emailVal);
          password = (EditText) findViewById(R.id.passwordVal);
          login = (TextView) findViewById(R.id.login);
          signup = (TextView) findViewById(R.id.signUP);
          fragment = new SignupFragment();
          signup.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  fragmentManager = getSupportFragmentManager();
                  fragmentTransaction = fragmentManager.beginTransaction();
  
                  fragmentTransaction.add(R.id.maine, fragment);
                  fragmentTransaction.addToBackStack("backfrag");
                  fragmentTransaction.commit();
              }
          });
  
  
  
  
  
  activity_main.xml
  
      &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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:orientation="vertical"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:id="@+id/maine"
      tools:context="com.hubbellindia.lightdemo1.MainActivity"&gt;
  
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="25sp"
          android:textColor="#000000"
          android:layout_gravity="center_horizontal"
          android:text="LOGIN" /&gt;
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:hint=" Enter Email"
          android:id="@+id/emailVal"
          android:background="@drawable/edit"
          android:layout_marginTop="40dp"
  
          /&gt;
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:hint=" Enter Password"
          android:id="@+id/passwordVal"
          android:background="@drawable/edit"
          android:layout_marginTop="40dp"
  
          /&gt;
      &lt;TextView
          android:layout_width="160dp"
          android:layout_height="40dp"
          android:text="LOGIN"
          android:gravity="center"
          android:background="#ee4356"
          android:id="@+id/login"
          android:textColor="#ffffff"
          android:textStyle="bold"
          android:layout_gravity="center_horizontal"
          android:layout_marginTop="40dp"/&gt;
      &lt;TextView
          android:layout_width="160dp"
          android:layout_height="40dp"
          android:text="Sign up"
          android:gravity="center"
          android:id="@+id/signUP"
         android:layout_marginLeft="80dp"
          android:textColor="#000000"
          android:textStyle="bold"
          android:layout_gravity="center_horizontal"
          android:layout_marginTop="10dp"/&gt;
  
  &lt;/LinearLayout&gt;
  
  SignUpFragment.java:
  
      public class SignupFragment extends Fragment {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_signup, container, false);
      }
  
      // TODO: Rename method, update argument and hook method into UI event
  
  
  }
  
  fragment_signup.xml:
  
      &lt;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="com.hubbellindia.lightdemo1.SignupFragment"&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
  
      &lt;LinearLayout
          android:id="@+id/activity_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="#ffffff"
          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="com.hubbellindia.lightdemo1.MainActivity"&gt;
  
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textSize="25sp"
              android:textColor="#000000"
              android:layout_gravity="center_horizontal"
              android:text="SIGNUP" /&gt;
          &lt;EditText
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:hint=" Enter Email"
              android:id="@+id/emailValNew"
              android:background="@drawable/edit"
              android:layout_marginTop="40dp"
  
              /&gt;
          &lt;EditText
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:hint=" Enter Password"
              android:id="@+id/passwordValNew"
              android:background="@drawable/edit"
              android:layout_marginTop="40dp"
  
              /&gt;
          &lt;TextView
              android:layout_width="160dp"
              android:layout_height="40dp"
              android:text="SIGNUP"
              android:gravity="center"
              android:background="#ee4356"
              android:id="@+id/signup"
              android:textColor="#ffffff"
              android:textStyle="bold"
              android:layout_gravity="center_horizontal"
              android:layout_marginTop="40dp"/&gt;
  
  
      &lt;/LinearLayout&gt;
  
  
  &lt;/FrameLayout&gt;
  </code></pre>