title: How to add an Android fragment to an activity?
body: <p>I would like to add a fragment to my main activity, so I have this fragment class (TitleFragment.java):</p>
  
  <pre><code>package com.myapp.app1;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class TitleFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_title, container, false);
      }
  }
  </code></pre>
  
  <p>Next is the actual content of my fragment, contained in <code>fragment_title.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
         &lt;ImageView 
          android:id="@+id/logo_iv"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/logo_main"
          android:contentDescription="@string/app_name"
          android:scaleType="fitStart"
          android:adjustViewBounds="true" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And inside my <code>activity_main.xml</code> I have this snippet amongst the regular content of the activity:</p>
  
  <pre><code>&lt;fragment 
              android:name="com.myapp.app1.TitleFragment"
              android:id="@+id/title_fragment"
              android:layout_width="0dp"
              android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>Is this method a correct way to create a fragment? My app just crashes and the LogCat seems to indicate it's to do with inflating the fragment view, but I'm not sure.</p>
  
  <p>By the way the reason for this fragment is to have the app logo (image and some updateable text) that exists on every page, is this a good method to do something like that? Sorry for my newbie questions.</p>