I have an activity where CollapsingToolbarLayout is combined with ViewPager.
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView />
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<CardView>
<LinearLayout>
<TabLayout/>
<ViewPager/>
</LinearLayout>
</CardView>
</CoordinatorLayout>
ViewPager contains pages with NastedScrollViews or RecyclerViews. Everything works well except when I scroll content of ViewPager up/down and CollapsingToolbarLayout is in the middle of collapsing or expanding and finger slightly moves left or right it interrupts collapsing/expanding and starts to scroll pages.
How do I prevent this ?
I know how to prevent ViewPager from scrolling. But cant figure out how do I subscribe for CollapsingToolbarLayout changes. Or maybe should I listen to CoordinatorLayout ro implement CoordinatorLayout.Behavior that notifies me...
Thanks.
Related
I have a layout hierarchy like this:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<LinearLayout>
//Conteiner with some other views. I want to hide this section on scrall.
</LinearLayout>
<TabLayout/> // I want to make this TabLayout like sticky header on scroll.
<ViewPager/> // Recycler inside
</CoordinatorLayout>
I think I can do it by pitting the content container and tab layout as different VIewHolders into the recyclerView. And then add some Item decoration to make the tab layout sticky. But I think it is I can achieve such behavior using the Coordinator layout. I will appreciate any suggestions
I've got this layout setup in my app:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar/>
</AppBarLayout>
<NestedScrollView>
<ViewPager>
<SwipeRefreshLayout>
<RecyclerView/>
</SwipeRefreshLayout>
</ViewPager>
</NestedScrollView>
</CoordinatorLayout>
I'm hiding the Toolbar on scroll down, to gain more space for my content. With a few exceptions when you fling/scroll with sudden movements in different directions, all works pretty well. The only problem is, as you can see in this gif
that when the Toolbar is hidden, after swiping to the next month, a scroll/fling to reveal the Toolbar automatically triggers the pull-to-refresh of the SwipeRefreshLayout. I'd really like to inhibit this as a refresh potentially triggers a login with username/password/one-time-pin.
I've tried to subclass the NestedScrollView and consume the scroll/fling when a) the RecyclerView is at the top and b) the Toolbar is not visible but so far to no success. Any pointers on how to do this by the book?
My structure is looking like that:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
...
</CollapsingToolbarLayout>
<TabLayout/>
</AppBarLayout>
<ViewPager/>
</CoordinatorLayout>
ViewPager wraps it's content each time when the page is changed but never takes height more than an available height (like match_parent). The problem in that when ViewPager height is less than the available height the AppBar is collapsing until it is not visible and there is a lot of empty space under the wrapped ViewPager. How can I implement behaviour when the ViewPager is less than content available height do not collapse more than needed?
By default, CollapsingToolbarLayout is being collapsed or expanded when user scrolls the view from NestedScrollView.
How can I turn off auto expanding? What I want to achieve is a toolbar which I can expand or collapse only by calling AppBarLayout::setExpanded.
OK, I've found an answer. In order to make toolbar collapsing on the screen scrolled, we have to create following layout hierarchy:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Toolbar />
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView>
<!-- content -->
</NestedScrollView>
</CoordinatorLayout>
In order to turn off this feature (to make scrolling not cause collapsing the toolbar), we have just to replace NestedScrollView with ScrollView.
I have a problem with the below layout structure:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar>
</AppBarLayout>
<DrawerLayout
app:layout_behavior="appbarScrollingBehavior">
<ViewPager>
<ListView>
</DrawerLayout>
</CoordinatorLayout>
Everything works fine, but there is a problem with the scrolling of the AppBarLayout. Namely, the ListView acting as a side drawer is "pushed" downwards by the height of the Toolbar. This causes the last element to be visible only when the Toolbar is completely collapsed :-(
Any ideas why this is happening? I already tried replacing the ListView with a RecyclerView, but it did not help. It seems that the CoordinatorLayout is measuring children first and only then moving them according to the Behaviors.