Ich habe eine Aktivität, die 3 Registerkarten hat. Jede Tabseite ist ein Fragment, das eine RecyclerView anzeigt. Eines der Fragmente enthält FloatingActionButton. Ich implementiere diesen Button im Layout des Fragments. Ich mache es auch unten rechts im Fragment statisch.Zeige/Verberge FloatingActionButton auf ViewPager Swipe
Fragment Layout:
- CoordinatorLayout
- RecyclerView
- FAB (without any behavior)
In Aktivität Layout, ich habe:
- CoordinatorLayout
- AppBarLayout
- Toolbar
- TabLayout (SmartTabLayout)
- ViewPager
Das Problem ist nun die FAB ist halb versteckt von der Ansicht, wenn Toolbar erweitert wird, sondern vollständig angezeigt, wenn Die Symbolleiste ist minimiert. Obwohl dies nicht geschieht, wenn ich die FAB-Taste in Aktivität selbst implementiere. Aber ich möchte nicht den Button in allen Fragmenten haben. Ich gebe es nur in das erste Fragment.
Hier ist ein Gif, das ich gemacht habe, um das klarer zu erklären.
XML für Aktivität Layout:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
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="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/color_primary"
app:layout_scrollFlags="scroll|enterAlways" />
<com.ogaclejapan.smarttablayout.SmartTabLayout
android:id="@+id/viewpagertab"
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:background="@color/color_primary" />
</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.CoordinatorLayout>
XML für Fragment-Layout:
<?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"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/card_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_plus_white_48dp"
app:layout_anchor="@id/card_list"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Meine Frage ist, wie kann ich so machen, dass die Taste bleibt sichtbar, wenn recyclerview gescrollt ? In
Ich denke, ich werde Ihre Lösung verwenden, da sie mehr Funktionalität bietet. Danke für Ihren Vorschlag! – AimanB
@AimanB Eine weitere Sache, stellen Sie sicher, dass Sie die neueste Version der Support-Design-Bibliothek verwenden, sie behoben viele Probleme in den neuesten Versionen, eine der Standard-Animationen mit den 'show()' und 'hide()' Methoden. –