title: Android Fragment layout is out of screen
body: <p>So I've got a TabbedActivity with an additional class extending fragment but the list just won't stay inside my screen.</p>
  
  <p><a href="https://i.stack.imgur.com/vnLZW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vnLZW.png" alt="List item out of screen"></a></p>
  
  <p>As you may see there should be an additional H at the screen's bottom.</p>
  
  <p>Here's my fragment layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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: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=".CreateGameActivity"&gt;
  
      &lt;TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginBottom="@dimen/activity_vertical_margin"
          android:layout_marginLeft="@dimen/activity_horizontal_margin"
          android:layout_marginStart="@dimen/activity_horizontal_margin"
          android:layout_marginTop="@dimen/activity_vertical_margin"
          android:text="@string/create_game_participants_tab_title"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textColor="@color/colorPrimary"/&gt;
  
      &lt;ListView
          android:id="@+id/listParticipants"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_below="@+id/textView4"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"/&gt;
  
      &lt;TextView
          android:id="@+id/textNoParticipants"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView4"
          android:layout_alignStart="@+id/textView4"
          android:layout_alignTop="@+id/listParticipants"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:text="@string/no_participants"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>which is loaded by following onCreateView() method</p>
  
  <pre><code>View view = inflater.inflate(R.layout.fragment_create_game_participants_layout, container, false);
  
  ListView listParticipants = (ListView) view.findViewById(R.id.listParticipants);
  TextView textNoParticipants = (TextView) view.findViewById(R.id.textNoParticipants);
  
  List&lt;String&gt; list = new LinkedList&lt;&gt;();
  if (savedInstanceState != null &amp;&amp; savedInstanceState.containsKey("participants"))
      list.addAll((List&lt;String&gt;)savedInstanceState.getSerializable("participants"));
  else {
      SharedPreferences prefs = context.getSharedPreferences("participants", Context.MODE_PRIVATE);
      list.addAll(prefs.getStringSet("lastParticipants", new HashSet&lt;&gt;()));
  }
  
  ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, android.R.id.text1, list);
  listParticipants.setAdapter(adapter);
  
  SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(
          listParticipants,
          new SwipeDismissListViewTouchListener.DismissCallbacks {
              boolean canDismiss(int position) {
                  return true;
              }
  
              void onDismiss(ListView listView, int[] reverseSortedPositions) {
                  for (int position : reverseSortedPositions)
                      list.removeAt(position);
              }
          });
  listParticipants.setOnTouchListener(touchListener);
  listParticipants.setOnScrollListener(touchListener.makeScrollListener());
  
  return view;
  </code></pre>
  
  <p>Fragments are created using their constructor and loaded in activities onCreate() by</p>
  
  <pre><code>super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_create_game_activity_tabbed)
  
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  supportActionBar.setDisplayHomeAsUpEnabled(true);
  
  SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
      // Set up the ViewPager with the sections adapter.
  viewPager.setAdapter(mSectionsPagerAdapter);
  
  TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  tabLayout.setupWithViewPager(viewPager)
  </code></pre>
  
  <p>And finally my tabbed activities layout.xml is defined like this</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/main_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context="janniskaiser.matchplanner.CreateGameActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/appbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:paddingTop="@dimen/appbar_padding_top"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:popupTheme="@style/AppTheme.PopupOverlay"
              app:layout_scrollFlags="scroll|enterAlways"&gt;
  
          &lt;/android.support.v7.widget.Toolbar&gt;
  
          &lt;android.support.design.widget.TabLayout
              android:id="@+id/tabs"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" /&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"/&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="end|bottom"
          android:layout_margin="@dimen/fab_margin"
          android:src="@drawable/ic_ok" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>