ScrollingViewBehavior的ListView控件控件、ScrollingViewBehavior、ListView

2023-09-05 05:25:26 作者:趁时光还在﹏

我用两个活动 AppBarLayout 工具栏 TabLayout 从支持库22。

I have two activities using AppBarLayout with a Toolbar and TabLayout from support library 22.

两者的布局是pretty的相似:A 工具栏上方,下方 TabLayout ,它下面的一个 ViewPager 含3 片段秒。

The layout of both is pretty similar: A Toolbar at the top, below it TabLayout, below it a ViewPager containing 3 Fragments.

第一个活动的片段有一个 RecyclerView , 第二项活动的片段正在使用的ListView 代替。

The first activity's Fragment has a RecyclerView, the second activity's Fragment is using a ListView instead.

从 https://github.com/chrisbanes/cheesesquare的滚动工具栏例子采用做工精细的第一个活动的 RecyclerView ,但在与的ListView

我试图创建一个自定义的 ListViewScrollBehavior 扩展 AppBarLayout.ScrollingViewBehavior ,但至今没有运气。 该的TouchEvent 取值滚动的ListView (垂直)时,传递到自定义类只为横向滚动,但不是。

I've tried created a custom ListViewScrollBehavior that extends AppBarLayout.ScrollingViewBehavior, but so far no luck. The TouchEvents are passed to the custom class only for horizontal scrolling, but not when scrolling the ListView (vertically).

任何方式使用 CoordinatorLayout 的ListView

推荐答案

唯一的解决方案,使现在的工作就是用这样的:

The only solution to make it work now is to use this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     listView.setNestedScrollingEnabled(true);
}

这显然只适用于棒棒糖。

It will obviously only work on Lollipop.