- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何仅在 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/
我目前状态的视频,以便更好地了解我的情况: video RecyclerView 上面的所有东西都在 AppbarLayout 里面 具有类似行为的 reddit 应用示例: video 目标: 1-
我正在创建一个带有 header 的 RecyclerView,当您向上滚动 RecyclerView 时 header 会折叠。我可以通过下面的布局非常接近地实现这一点,使用透明的 AppBarLa
我有一个 AppBarLayout 和 NestedScrollView。我希望 NestedScrollView 每当它向下滚动时,AppBarLayout 也应该优雅地展开,而 NestedScr
我正在尝试获取 AppBarLayout 的布局参数,但出现此错误。 java.lang.ClassCastException: android.support.design.widget.Coord
我正在为我的应用程序实现自定义 header 。在 AppBarLayout 中,我使用工具栏和我的自定义布局(名为 CustomHeader)。 我的 CustomHeader 有左下角和右下角圆角
我是编程新手,我想添加一个设置菜单按钮。 就像图片上的一样,我的应用程序没有显示三点按钮。 MainActivity.java : public class MainActivity extends
我有一个带有 fragment 的 ViewPager,其中包含一个 RecyclerView。 CollapsingTollbarLayout 位于 ViewPager 之上。一切正常,除了在 Re
我想做这个, 在 Android Studio 的预览中看起来不错,但在运行时我得到这个 正如您在屏幕开头看到的那样,颜色是白色,我想添加我自己的颜色,在本例中为绿色。 最初它使用的是 Cordina
我正在使用此布局来尝试实现可折叠的应用栏。 android:theme="@style/ThemeOverlay.AppCompat.Dark"
所以我有一个带有 AppBarLayout 和 CollapsingToolbarLayout 的 CoordinatorLayout。这是展开(左图)和折叠(右图)时的样子 我遇到的第一个问题是,当
我尽量让红色布局滚动,这样他就隐藏了,TabLayout 就留在了最上面 我需要红色布局来为我填充圆形头像的高度。我尝试将TabLayout滚动到顶部,红色布局继续滚动隐藏? 无法发送图片,请点击链接
我正在尝试从顶部为 AppBarLayout 设置动画,就像 this 中的工具栏一样视频。 这是我的布局
我需要我的 AppBarLayout 具有透明背景。 当我将 AppBarLayout 的背景更改为具有 @null 或 @android:color/transparent 时,我在工具栏的边框处看
使用 AppBarLayout 时出错,我尝试了 Clean Project 和 Rebuild Project,但它们没有用。 运行程序没有问题。这是为什么? XML 文件:
我想要实现的结果与图片上的结果几乎相同,但没有折叠并且在工具栏文本下有选项卡布局。我使用 CollapsingTollbarLayout 完成了它,但如果我不希望它折叠,我认为这不是一个好方法。我应该
我在 CoordinatorLayout 和 RecyclerView 中使用 AppBarLayout、CollapsingToolbarLayout 创建了折叠透明搜索栏。让 recyclerVi
Android Google Play 应用如何在用户点击 AppBarlayout 时动态改变颜色? 我尝试了以下方法 tabLayout.setOnTabSelectedListener(new
在页面上的任意位置下拉(过度滚动)时,我一直在努力实现 AppBarLayout 的缩放效果。 期望效果示例: https://android-arsenal.com/details/1/4443 我
当我尝试为 AppBarLayout 设置一个特定的高度值时,阴影完全消失了。 这是错误还是预期的行为? 我使用的是设计库的 26.0.0 版。 最佳答案 设置属性动画
我在 AppBarLayout 中使用了 CollapsingToolbarLayout,用户可以使用 AppBarLayout 中的 setExpanded(boolean) 方法展开或折叠它。 问
我是一名优秀的程序员,十分优秀!