Android FAM没有';当我向下滚动listview时,它不会消失(隐藏)

Android FAM没有';当我向下滚动listview时,它不会消失(隐藏),android,floating-action-button,Android,Floating Action Button,当我向下滚动listview时,FAM不会消失(隐藏), 我使用了app:layou_behavior=“com.teroject.teroject.FloatingActionMenuBehavior” FloatingActionMenuBehavior java类在代码下面,但正如我所说的,什么都没有发生! 我该怎么办 主要活动的xml: <LinearLayout android:orientation="vertical" android:layout_width="match_

当我向下滚动listview时,FAM不会消失(隐藏), 我使用了app:layou_behavior=“com.teroject.teroject.FloatingActionMenuBehavior” FloatingActionMenuBehavior java类在代码下面,但正如我所说的,什么都没有发生! 我该怎么办

主要活动的xml:

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/tools">
<include
    layout="@layout/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</include>

<!-- This LinearLayout represents the contents of the screen  -->
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/flContent"
        android:orientation="vertical">

        <!--TabLayout XML-->
        <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/container_tab"
            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:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:tabMode="fixed"
                    app:tabGravity="fill"
                    android:background="@color/colorPrimary"/>
            </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"  />

            <com.github.clans.fab.FloatingActionMenu
                android:id="@+id/menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:menu_fab_size="normal"
                app:menu_showShadow="true"
                app:menu_shadowColor="#66000000"
                app:menu_shadowRadius="1dp"
                app:menu_shadowXOffset="1dp"
                app:menu_shadowYOffset="1dp"
                app:menu_colorNormal="#2e782e"
                app:menu_colorPressed="#2aa749"
                app:menu_colorRipple="#99FFFFFF"
                app:menu_animationDelayPerItem="80"
                app:menu_icon="@drawable/fab_add"
                app:menu_buttonSpacing="0dp"
                app:menu_labels_margin="0dp"
                app:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
                app:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
                app:menu_labels_paddingTop="4dp"
                app:menu_labels_paddingRight="8dp"
                app:menu_labels_paddingBottom="4dp"
                app:menu_labels_paddingLeft="8dp"
                app:menu_labels_padding="8dp"
                app:menu_labels_textColor="#FFFFFF"
                app:menu_labels_textSize="14sp"
                app:menu_labels_cornerRadius="3dp"
                app:menu_labels_colorNormal="#08ae7c"
                app:menu_labels_colorPressed="#71e1b0"
                app:menu_labels_colorRipple="#99FFFFFF"
                app:menu_labels_showShadow="true"
                app:menu_labels_singleLine="false"
                app:menu_labels_ellipsize="none"
                app:menu_labels_maxLines="-1"
                app:menu_labels_position="left"
                app:menu_openDirection="up"
                app:menu_backgroundColor="@android:color/transparent"
                android:layout_margin="@dimen/fab_margin"
                android:layout_gravity="bottom|right"
                app:layout_behavior="com.teroject.teroject.FloatingActionMenuBehavior">


                <com.github.clans.fab.FloatingActionButton
                    android:id="@+id/menu_item_creating_team"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_add_team"
                    app:fab_size="mini"
                    app:fab_colorNormal="#08ae7c"
                    app:fab_colorPressed="#71e1b0"
                    app:fab_colorRipple="#99FFFFFF"
                    app:fab_label="ایجاد تیم"/>

                <com.github.clans.fab.FloatingActionButton
                    android:id="@+id/menu_item_creating_project"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_add_project"
                    app:fab_size="mini"
                    app:fab_colorNormal="#08ae7c"
                    app:fab_colorPressed="#71e1b0"
                    app:fab_colorRipple="#99FFFFFF"
                    app:fab_label="ایجاد پروژه"/>
                <com.github.clans.fab.FloatingActionButton
                    android:id="@+id/menu_item_creating_duty"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_add_duty"
                    app:fab_size="mini"
                    app:fab_colorNormal="#08ae7c"
                    app:fab_colorPressed="#71e1b0"
                    app:fab_colorRipple="#99FFFFFF"
                    app:fab_label="ایجاد وظیفه"/>
                <com.github.clans.fab.FloatingActionButton
                    android:id="@+id/menu_item_sending_msg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_new_message"
                    app:fab_size="mini"
                    app:fab_colorNormal="#08ae7c"
                    app:fab_colorPressed="#71e1b0"
                    app:fab_colorRipple="#99FFFFFF"
                    app:fab_label="ارسال پیام"/>

            </com.github.clans.fab.FloatingActionMenu>


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

    </LinearLayout>
    <!-- The navigation drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:background="@color/colorNavDrawerBackColor"
        app:menu="@menu/drawer_view"
        app:theme="@style/nav_drawer_style" />
</android.support.v4.widget.DrawerLayout>

FloatingActionMenuBehavior.java类:

public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior {
private float mTranslationY;

public FloatingActionMenuBehavior(Context context, AttributeSet attrs) {
    super();
}

@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    if (child instanceof FloatingActionMenu && dependency instanceof Snackbar.SnackbarLayout) {
        this.updateTranslation(parent, child, dependency);
    }

    return false;
}

private void updateTranslation(CoordinatorLayout parent, View child, View dependency) {
    float translationY = this.getTranslationY(parent, child);
    if (translationY != this.mTranslationY) {
        ViewCompat.animate(child)
                .cancel();
        if (Math.abs(translationY - this.mTranslationY) == (float) dependency.getHeight()) {
            ViewCompat.animate(child)
                    .translationY(translationY)
                    .setListener((ViewPropertyAnimatorListener) null);
        } else {
            ViewCompat.setTranslationY(child, translationY);
        }

        this.mTranslationY = translationY;
    }

}

private float getTranslationY(CoordinatorLayout parent, View child) {
    float minOffset = 0.0F;
    List dependencies = parent.getDependencies(child);
    int i = 0;

    for (int z = dependencies.size(); i < z; ++i) {
        View view = (View) dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
            minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
        }
    }

    return minOffset;
}

/**
 * onStartNestedScroll and onNestedScroll will hide/show the FabMenu when a scroll is detected.
 */
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child,
                                   View directTargetChild, View target, int nestedScrollAxes) {
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL ||
            super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target,
                    nestedScrollAxes);
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target,
                           int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
            dyUnconsumed);
    FloatingActionMenu fabMenu = (FloatingActionMenu) child;
    if (dyConsumed > 0 && !fabMenu.isMenuButtonHidden()) {
        fabMenu.hideMenuButton(true);
    } else if (dyConsumed < 0 && fabMenu.isMenuButtonHidden()) {
        fabMenu.showMenuButton(true);
    }
}
公共类FloatingActionMenuBehavior扩展了CoordinatorLayout.Behavior{
私人浮动MTransation;
public FloatingActionMenuBehavior(上下文、属性集属性){
超级();
}
@凌驾
公共布尔布局依赖项(协调布局父项、视图子项、视图依赖项){
返回Snackbar.Snackbar布局的依赖实例;
}
@凌驾
公共布尔onDependentViewChanged(协调布局父项、视图子项、视图依赖项){
if(floatingAction菜单的子实例和Snackbar.Snackbar布局的依赖实例(&D)){
此.updateTranslation(父、子、依赖项);
}
返回false;
}
私有void updateTranslation(协调布局父项、视图子项、视图依赖项){
float translationY=this.getTranslationY(父级,子级);
if(translationY!=this.mttranslationy){
ViewCompat.animate(子对象)
.cancel();
if(Math.abs(translationY-this.mtransationy)==(float)dependency.getHeight()){
ViewCompat.animate(子对象)
.translationY(translationY)
.setListener((ViewPropertyAnimatorListener)null);
}否则{
ViewCompat.setTranslationY(子对象,translationY);
}
this.mTranslationY=translationY;
}
}
private float GetTranslation(CoordinatorLayout父级,View子级){
浮动最小偏移=0.0F;
List dependencies=parent.getDependencies(child);
int i=0;
对于(int z=dependencies.size();i0&&!fabMenu.isMenuButtonHidden()){
fabMenu.hideMenuButton(真);
}else if(dyconsumered<0&&fabMenu.isMenuButtonHidden()){
fabMenu.showMenuButton(true);
}
}

}

如果调用
ListView.setNestedScrollingEnabled(true)
,则滚动行为仅适用于ListView,并且仅适用于api-21及更高版本


解决此问题的正确方法是将ListView转换为RecyclerView,该视图支持在所有支持的api级别上嵌套滚动。

如果调用
ListView.setNestedScrollingEnabled(true)
,滚动行为仅适用于ListView,并且仅适用于api-21及以上版本。修复此问题的正确方法是将ListView转换为RecyclerView,它支持在所有支持的api级别上嵌套滚动。@DanielNugent那么你的意思是如果我将ListView转换为RecyclerView,上述代码(我的代码)将起作用?是的,应该可以起作用。@DanielNugent所以假设我将其转换为RecyclerView,我是否应该将此代码放入recyclerView.setNestedScrollingEnabled(true)?否,不需要使用recyclerView,它在默认情况下处于启用状态