以编程方式滚动到NestedScrollView的顶部 [英] Programmatically scroll to the top of a NestedScrollView

查看:710
本文介绍了以编程方式滚动到NestedScrollView的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以通过触发父级的滚动事件来以编程方式滚动到NestedScrollView的顶部? smoothScrollTo(x, y)不会将滚动事件委托给NestedScrollingParent.

Is there a way to programmatically scroll to the top of a NestedScrollView by also triggering the scroll events for the parent? smoothScrollTo(x, y) doesn't delegate the scroll events to the NestedScrollingParent.

推荐答案

我设法做到了(动画滚动):

I managed to do it (animated scrolling):

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
    behavior.onNestedFling(coordinatorLayout, appBarLayout, null, 0, 10000, true);
}

其中10000是y方向的速度.

这篇关于以编程方式滚动到NestedScrollView的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆