0

Im pretty new to Android development and i've got a little issue with my first application. It would be very nice if someone could help to find the solution. I've searched but didn't find one. My idea is that it maybe goes out of the screen because the relative layout doesn't recognize that there are tabs above...
My problem is following, I have this xml layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">`

  <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_alignParentBottom="true"
     android:layout_alignParentEnd="true"
     android:layout_margin="@dimen/fab_margin"
     app:srcCompat="@android:drawable/ic_dialog_email"
     android:layout_alignParentRight="true" />
</RelativeLayout>

And this is how it should look like: Screenshot
And this is how it actually looks like: Screenshot

Edit: This is just a fragment -> here is the container:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<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">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>

<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" />

</android.support.design.widget.CoordinatorLayout>
patwis
  • 136
  • 1
  • 13
  • Try removing the alignParent tags. – AlphaQ Nov 19 '16 at 18:01
  • But I want the FloatingActionButton to be in the bottom right corner. Without the alignParent tags the button is in the top left corner. @AlphaQ – patwis Nov 19 '16 at 18:05
  • The android:layout_gravity="bottom|end" should put the fab in its position. – AlphaQ Nov 19 '16 at 18:09
  • Is the RelativeLayout correct used here? Or maybe I should use a LinearLayout as said [here](http://stackoverflow.com/questions/6575409/linearlayout-layout-gravity-bottom-not-working-on-horizontal-linearlayout) @AlphaQ – patwis Nov 19 '16 at 18:12

1 Answers1

0

Try using this:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />

and android:layout_marginBottom="?attr/actionBarSize" in your activity_main.xml viewPager

Swr7der
  • 849
  • 9
  • 28
  • The layout_gravity doesn't seem to work as it should... Because now the button is in the top left corner... @Swr7der – patwis Nov 19 '16 at 18:08
  • I think you should use some other layout, (but it's working fine for me). Can you post more details? The activitymain and contentmain of tabbed activity that you are using? – Swr7der Nov 19 '16 at 18:25
  • I posted in the main post now the xml code of the container of the app... What else should I show? I don't edit the layout via java yet. @Swr7der – patwis Nov 19 '16 at 18:28
  • updated post, try that code and tell the result @patwis – Swr7der Nov 19 '16 at 18:33
  • Nice tipp! But the layout_gravity still doesn't work. But when I added the layout_alignParentBottom / Right it worked. – patwis Nov 19 '16 at 19:20
  • Put **android:layout_marginBottom="?attr/actionBarSize"** as this is necessary as when you would start adding list in the fragment, the last item may be hidden. So I would suggest using that. And you can upvote and/or accept the answer if you liked the explanation just as a tip ;) Keep coding :) – Swr7der Nov 19 '16 at 19:24