gpt4 book ai didi

带有用于自定义布局的 ListView 的 Android FAB 行为

转载 作者:行者123 更新时间:2023-11-30 01:43:48 24 4
gpt4 key购买 nike

我想实现类似于这个例子的行为

image

但没有工具栏移动和自定义 View 不适用于 FAB。所以,首先我希望看到类似于 https://www.google.com/design/spec/components/bottom-sheets.html 的布局。 (它可以是简单的 LinearLayout 放置在屏幕底部,带有一些 subview )当我开始向下滚动 ListView 时隐藏,当我向上滚动一点时出现。深入挖掘网络但没有发现真正有用的东西。提前致谢。

最佳答案

首先你需要扩展default FAB behavior , 为了在 Snackbar 时保持 FAB 行为显示。否则你会看到它在 Snackbar 时没有向上翻译。弹出。

仅对垂直滚动使用react:

@Override
public boolean onStartNestedScroll(CoordinatorLayout parent,
View child, View target, View target,int scrollAxes) {
return (scrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
}

一旦你有垂直嵌套滚动累积滚动了多少。当您滚动到 FAB 高度时开始翻译 FAB:

    Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dx, int dy, int[] consumed) {
if (dy > 0 && mTotalDy < 0 || dy < 0 && mTotalDy > 0) {
mTotalDy = 0;
}

mTotalDy += dy;
if ( mTotalDy > child.getHeight()
&& child.getVisibility() == View.VISIBLE) {
//translate to it's height, offscreen, set visbility to gone at end of translation animation
} else if (mTotalDy < 0
&& child.getVisibility() == View.GONE) {
//translate to 0 set visbility to visible at end of translation animation
}

}

mTotalDymTotalDy 大于我们向下滚动的 FAB 高度时我们正在向上滚动。

您还应该注意 onNestedPreFling() 中的嵌套 throw 方法。在 velocityY < 0 时隐藏 FAB并在 velocityY > 0 时显示,所有这些条件仅当Math.abs(velocityY) > Math.abs(velocityX) .换句话说,只有当有垂直甩动时。

关于带有用于自定义布局的 ListView 的 Android FAB 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34027192/

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