ScrollingViewBehavior for ListView

marmor picture marmor · Jun 3, 2015 · Viewed 18.7k times · Source

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

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

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

The scrollable Toolbar example from https://github.com/chrisbanes/cheesesquare is working fine on the first activity using the RecyclerView, but on with the 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).

Any way to use a CoordinatorLayout with ListView?

Answer

Nicolas POMEPUY picture Nicolas POMEPUY · Jun 6, 2015

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.