title: Android - Change RelativeLayout to Fragment
body: <p>I want to "remake" my app.
  I already write an app and it works OK. But, it use Activity and Spinner to switch between screens - that is too uncomfortable and slow. 
  I here find an example of Fragment usage for user-comfortable usage and fast switching beetween screens with swiping:
  <a href="http://www.theappguruz.com/blog/android-tab-layout-with-swipeable-views" rel="nofollow noreferrer">http://www.theappguruz.com/blog/android-tab-layout-with-swipeable-views</a> </p>
  
  <p>But I cant set RelativeLayout for it from my app, because it use Fragment.
  Is there a way to "copy-paste" the markup file (*.xml) without making fundamental changes in the application?</p>
  
  <p>I tried to do it (the commented line of code), but it does not work.</p>
  
  <p><strong>FirstTab.java</strong></p>
  
  <pre><code>import android.graphics.Color;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.Gravity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.LinearLayout.LayoutParams;
  import android.widget.TextView;
  
  public class FirstTab extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          /*View view=inflater.inflate(R.layout.tab_first, container, false);
          Button imageView = (Button) getView().findViewById(R.id.btn_quit);
          return view;*/
  
          TextView tv = new TextView(getActivity());
          tv.setText("First Tab");
          tv.setGravity(Gravity.CENTER);
          tv.setTextColor(Color.WHITE);
          tv.setWidth(LayoutParams.MATCH_PARENT);
          tv.setHeight(LayoutParams.MATCH_PARENT);
          tv.setBackgroundColor(Color.RED);
          tv.setTextAppearance(getActivity(),android.R.style.TextAppearance_Large);
          return tv;
      }
  }
  </code></pre>
  
  <p><strong>first_tab.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      android:paddingBottom="5sp"
      android:paddingTop="5sp"
      android:paddingRight="5sp"
      android:paddingLeft="5sp"
      android:background="@color/colorPrimary"&gt;
  
      &lt;Spinner
          android:entries="@array/activity_list"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/spinner"
          android:layout_alignRight="@+id/view1"
          android:layout_alignEnd="@+id/view1"
          android:layout_toRightOf="@+id/btn_quit"
          android:layout_toEndOf="@+id/btn_quit"
          android:layout_alignBottom="@+id/btn_quit"
          android:layout_alignParentTop="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Close\napp"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:id="@+id/btn_quit"
          android:onClick="quit"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;View
          android:layout_width="fill_parent"
          android:layout_height="5dp"
          android:background="@android:color/holo_orange_light"
          android:id="@+id/view1"
          android:layout_below="@+id/btn_quit"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true" /&gt;
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/eng_text"
          android:paddingTop="10dp"
          android:paddingBottom="10dp"
          android:paddingLeft="10dp"
          android:paddingRight="10dp"
          android:background="@android:color/white"
          android:hint="Enter text"
          android:minLines="1"
          android:layout_below="@+id/view1"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
          android:maxLines="7"/&gt;
  
      &lt;View
          android:layout_width="fill_parent"
          android:layout_height="5dp"
          android:background="@android:color/holo_orange_light"
          android:id="@+id/view"
          android:layout_below="@+id/eng_text"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true" /&gt;
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/morse_text"
          android:paddingTop="10dp"
          android:paddingBottom="10dp"
          android:paddingLeft="10dp"
          android:paddingRight="10dp"
          android:background="@android:color/white"
          android:hint="Get a code"
          android:minLines="1"
          android:layout_below="@+id/view"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
          android:maxLines="8" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Translate"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:id="@+id/trans_btn"
          android:layout_above="@+id/btn_sound"
          android:layout_centerHorizontal="true"
          android:layout_alignParentRight="true"
          android:onClick="translate"/&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="left|bottom"
          android:text="Play\ncode:"
          android:id="@+id/play_label"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/trans_btn"
          android:layout_toLeftOf="@+id/btn_sound"
          android:layout_toStartOf="@+id/btn_sound" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/btn_sound"
          android:layout_alignParentBottom="true"
          android:layout_toLeftOf="@+id/btn_flash"
          android:layout_toStartOf="@+id/btn_flash"
          android:padding="2dp"
          android:onClick="play_sound"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/btn_flash"
          android:layout_alignParentBottom="true"
          android:layout_alignRight="@+id/view"
          android:layout_alignEnd="@+id/view"
          android:padding="2dp"
          android:onClick="play_flash"/&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Current input\nlanguage:"
          android:id="@+id/cur_lang"
          android:layout_alignTop="@+id/trans_btn"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/btn_flag"
          android:layout_alignTop="@+id/cur_lang"
          android:layout_toRightOf="@+id/cur_lang"
          android:layout_toEndOf="@+id/cur_lang"
          android:enabled="false"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/w2wyO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w2wyO.png" alt="First two screenshoots - what I have; Third - what I want to do"></a></p>