我有一个FloatingActionButton,它实现了向下滚动时隐藏它的行为,并在向上滚动时显示它.
但是,有时当我向上滚动时,它会隐藏自己,然后再次出现.根据我的代码,这是不可理解的,因为它应该只在向下滚动时隐藏.
也许它与我的也在滚动的CollapsingToolbar有关?
这是我的布局:
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:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:focusableInTouchMode="true"
android:clickable="true"
android:layoutDirection="rtl"
android:fitsSystemWindows="true"
android:id="@+id/drawer_layout">
android:id="@+id/mainCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layoutDirection="rtl"
android:background="#EEEEEE"
android:clickable="true">
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/toolbar_layout">
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:collapsedTitleGravity="right|top"
app:expandedTitleGravity="bottom|right"
app:expandedTitleMarginBottom="64dp"
app:collapsedTitleTextAppearance="@style/CollapsedTitleTextAppearance"
app:expandedTitleTextAppearance="@style/ExpandedTitleTextAppearance"
app:expandedTitleMarginEnd="0dp"
app:expandedTitleMarginStart="30dp">
android:id="@+id/headerImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:background="@drawable/soldier" />
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/scrim_top"
app:layout_collapseMode="pin" />
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_gravity="bottom"
android:layout_alignBottom="@+id/headerImage"
android:background="@drawable/scrim_bottom" />
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="104dp"
android:gravity="top"
app:titleTextColor="@color/White"
android:layout_gravity="right"
android:layoutDirection="rtl"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_collapseMode="pin"
app:contentScrim="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="15dp" />
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabIndicatorHeight="3dp"
android:layoutDirection="ltr"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@color/White"
app:tabTextColor="@color/Black"
style="@style/MyCustomTabLayout"
app:tabMode="fixed"
app:tabGravity="fill">
android:icon="@drawable/ic_book_white_24px"
android:text="ספרים" />
android:icon="@drawable/soldierWhite"
android:text="הלכות" />
android:icon="@drawable/ic_home_white_24px"
android:text="בית" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content_frame"
android:visibility="gone"
android:animateLayoutChanges="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:behavior_overlapTop="0dp">
android:id="@+id/mainPager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_overlapTop="0dp"
/>
android:id="@+id/mainFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_marginTop="5dp"
android:elevation="8dp"
app:layout_behavior="@string/fab_scroll_translation_autohide_behavior"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorAccent"
android:src="@drawable/ic_perm_phone_msg_white_24px" />
android:id="@+id/miniFabFrame"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="20dp"
android:layout_marginBottom="80dp"
android:padding="0dp">
android:id="@+id/messageFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:elevation="8dp"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="@drawable/ic_textSMS_white_24px" />
android:id="@+id/callFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:elevation="8dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="@drawable/ic_call_white_24px" />
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:id="@+id/nav_view"
android:layoutDirection="rtl"
app:headerLayout="@layout/header"
app:menu="@menu/nav_menu" />
这是我的行为:
[Register("ToratHamachane.ScrollAwareFABBehavior")]
public class ScrollAwareFABBehavior : CoordinatorLayout.Behavior
{
public ScrollAwareFABBehavior(Context context,IAttributeSet attrs) : base(context,attrs)
{
}
public override bool OnStartNestedScroll(CoordinatorLayout coordinatorLayout,Java.Lang.Object child,View directTargetChild,View target,int nestedScrollAxes)
{
return nestedScrollAxes == ViewCompat.ScrollAxisVertical ||
base.OnStartNestedScroll(coordinatorLayout,child,directTargetChild,target,nestedScrollAxes);
}
public override void OnNestedScroll(CoordinatorLayout coordinatorLayout,int dxConsumed,int dyConsumed,int dxUnconsumed,int dyUnconsumed)
{
base.OnNestedScroll(coordinatorLayout,dxConsumed,dyConsumed,dxUnconsumed,dyUnconsumed);
var floatingActionButtonChild = child.JavaCast();
if (dyConsumed > 0 && floatingActionButtonChild.Visibility == ViewStates.Visible)
floatingActionButtonChild.Hide();
else if (dyConsumed < 0 && floatingActionButtonChild.Visibility != ViewStates.Visible)
floatingActionButtonChild.Show();
}
}
任何想法为什么会这样?
我很感激任何帮助.
谢谢.