How to disable collapsing/expanding a CollapsingToolbarLayout on view scrolled? - android

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.

Related

Hide view on scroll in a coordinator layout

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

How to inhibit swipe-to-refresh when Toolbar is hidden and RecyclerView at the top

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?

How to use collapsing toolbar inside the sliding up panel?

I want to use the collapsing toolbar layout inside the sliding up panel as its child. When expanded could be able to also expand and collapse the collapsing toolbar.
Note: Sliding up panel https://github.com/umano/AndroidSlidingUpPanel
Edit:
I want to achieve this
<SlidingUpPanel>
-CHILD 1 main content
-child 2 fragment
</SlidingUpPanel>
Now in the fragment
<coordinatorLayout>
<appbarlayout>
<collapsingToolBarLayout>
<ImageView/>
<ToolBar/>
</collapsingToolBarLayout>
</appBar>
<ListView behaviour='scrollingview' />
</coordinatorLayout>
The problem is when the collapsing layout is expanded and when i try to collapse it the collapses the sliding up panel instead of the collapsing layout.
How can i fix it??

Scrolling Toolbar in DrawerLayout in CoordinatorLayout

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.

How do I prevent ViewPager from scrolling while collapsing/expanding CollapsingToolbarLayout

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.

Categories

Resources