Flottant sur le Bouton d'Action dans une Activité, la façon de point d'ancrage à une recyclerview dans un fragment?

J'ai eu le même problème dans cette question Flottant sur le Bouton d'Action ne présentant pas entièrement à l'intérieur d'un fragment de

J'ai un tablayout dans mon activity_main et 2 onglets (avec différents fragments, l'un d'eux contient un recyclerView). Quand je mets le dans le fragment FAB,FAB n'a pas été pleinement montré jusqu'à ce que je défile vers le bas de la recyclerView.

Donc, j'ai déplacé mon FAB dans le activity_main.xml fichier dans le coordinator_layout widget comme suggéré dans la question et il fonctionne bien.

De cette façon, j'ai un FAB dans l'activité et non pas dans le fragment et je voudrais savoir comment à l'ancre, par exemple , mon fab à la recyclerview dans le fragment, par exemple pour laisser animer durant le recycleur de défilement?

Maintenant activity_main.xml avec un tablayout :

activity_main.xml

<android.support.design.widget.CoordinatorLayout 
    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.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true" >

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar1"
            android:background="?attr/colorPrimary"
            android:scrollbars="horizontal"
            app:tabMode="scrollable" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/ic_action_location_found"
        app:fabSize="normal" />
    </android.support.design.widget.CoordinatorLayout>

fragment.xml

<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/activity_vertical_margin" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/start_button"
        android:scrollbars="vertical" />


</RelativeLayout>
Merci de poser une question spécifique. Si c'est une réponse, veuillez entrer comme une réponse.

OriginalL'auteur ozzem | 2015-06-27