gpt4 book ai didi

android - 当我向下滚动 ListView 时,FAM 不会消失(隐藏)

转载 作者:行者123 更新时间:2023-11-30 01:03:59 25 4
gpt4 key购买 nike

当我向下滚动 ListView 时,FAM 不会消失(隐藏),我用过 app:layout_behavior="com.teroject.teroject.FloatingActionMenuBehavior"FloatingActionMenuBehavior java 类在代码下方,但正如我所说,什么也没发生!我该怎么办?

主要 Activity 的 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);
}
}

最佳答案

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

修复它的正确方法是将您的 ListView 转换为 RecyclerView,它支持在所有支持的 api 级别上进行嵌套滚动。

关于android - 当我向下滚动 ListView 时,FAM 不会消失(隐藏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39065613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com