FloatingActionButton appears below the screen when using TabLayout and ViewPager

Take a look at FABbelow:

Picture

He does not appear if I do not hide Toolbar. Here is my XML:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/toolbar"
    android:layout_marginTop="0dp"
    android:animateLayoutChanges="true"
    android:background="@android:color/white"
    android:layoutDirection="locale"
    android:orientation="vertical"
    android:padding="0dp">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="0dp" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@color/accent"
            android:src="@drawable/ic_add"
            app:layout_anchor="@id/list"
            app:layout_anchorGravity="bottom|end" />
    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

Why does this happen if I do not set the behavior for FAB? Is there any property that I have to add to everything so that I can prevent this behavior?

+4
source share
3 answers

FloatingActionButton Fragment Activity. , FAB , . getActivity().findViewByIf(id) Fragment onClickListener Fragment.

+3

RelativeLayout :

<android.support.design.widget.CoordinatorLayout
android:id="@+id/cLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="0dp" />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:background="@color/accent"
    android:src="@drawable/ic_add"
    app:layout_anchor="@id/list"
    app:layout_anchorGravity="bottom|end" />
<com.rey.material.widget.ProgressView
    android:id="@+id/progress_bar"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    app:pv_autostart="true"
    app:pv_circular="true"
    app:pv_progressMode="indeterminate"
    app:pv_progressStyle="@style/Material.Drawable.CircularProgress" />
</android.support.design.widget.CoordinatorLayout>
-1

, , . i.e recyclerView floatingActionButton

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"> 

          <android.support.v7.widget.RecyclerView
              android:id="@+id/list"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:layout_marginTop="0dp" />

                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:background="@color/accent"
                    android:src="@drawable/ic_add"
                    app:layout_anchor="@id/list"
                    app:layout_anchorGravity="bottom|end" /></RelativeLayout>
-1

Source: https://habr.com/ru/post/1653458/


All Articles