-2

I am trying to implement youtube like tabs.

Is there a way to achieve this with CoordinatorLayout, AppBarLayout and TabLayout ?

I already tried to change AppBarLayout height in onScrollListener in fragment, but it is causing some scroll flickering.

Youtube tabs

kejmil01
  • 95
  • 2
  • 7

1 Answers1

0

Definitely there's a way to do it. That's what AppBarLayout was born to do -- stuff like that.

But if you're trying to change the AppBarLayout height in an onScrollListener in a fragment, you have run far afield from the way those components are supposed to work.

Be forewarned that these components are fragile as heck, just barely do what they are supposed to do, are not well documented and they break easily. Doing something like hammering away at the AppBarLayout height would go far beyond "breaks easily", and venture well into the realm of "that's not really how it's supposed to work at all".

Putting the ListView (or RecyclerView) in a fragment may also go horribly wrong for all kinds of fairly obvious reasons relating lifecycle and order of instantiation of views.

I would suggest starting with a working sample for AppBarLayout, and moving your way forward incrementally from there. If you're using Android Studio, right click on your app folder, and select New/Activity/ScrollingActivity, and work your way from there.

Whether you can drive the AppBarLayout from a ListView or RecyclerView in a fragment or not, I couldn't say. I think you should be able to do that; but I'd suggest that you get a dummy listview working as a direct child of the activity first, and then try migrating it to a fragment afterward.

Expect it to be hard. And expect that you'll have to live with limitations of inflexible implementation. They do what they do. And do not like to do what they don't do.

Robin Davies
  • 7,547
  • 1
  • 35
  • 50