gpt4 book ai didi

android - 仅在 AppBarLayout 完全展开时启用 SwipeRefreshLayout

转载 作者:搜寻专家 更新时间:2023-11-01 08:35:07 25 4
gpt4 key购买 nike

如何仅在 AppBarLayout 完全展开时启用 SwipeRefreshLayout。我只需要在下一次滑动手势时启用刷新模式。现在,我试试看

appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, final int verticalOffset) {
refreshLayout.setEnabled(verticalOffset == 0);
}
});

当然可以!但它的工作方式并不像我需要的那样。当用户继续滑动手势时,此代码会立即启用刷新模式。我只需要在 AppBarLayout 扩展后的下一次滑动时启用它。
谁知道怎么做?

最佳答案

好吧,我遇到了同样的问题。这是我发现的。我的解决方案并不完美,但它对我有用。假设我们有一个 AppBarLayout 和 RecyclerView 包装在 SwipeRefreshLayout 中。注意力!检测到 Kotlin。

recyclerView.setOnTouchListener { _, motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_CANCEL
|| motionEvent.action == MotionEvent.ACTION_UP) {

// 0.5f is used because I have snap parameter for CollapsingToolbar
// and it automatically collapses/expands
// if user finishes his scroll action in the middle of collapsing
// so if AppBar is going to be completely expanded
// we need to enable SwipeRefreshLayout
swipeRefreshLayout.isEnabled =
(appBarLayout.collapsingPercentage() < 0.5f)
}
false
}

/**
* @return 1.0f if AppBarLayout is completely collapsed,
* 0.0f if completely expanded, percentage of
* total height collapsed when collapsing/expanding is in progress.
*/
fun AppBarLayout.collapsingPercentage()
= Math.abs(this.height - this.bottom) / this.totalScrollRange.toFloat()

关于android - 仅在 AppBarLayout 完全展开时启用 SwipeRefreshLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37379491/

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