AppBarLayout to scroll only when scrolling upward and NOT when scrolling downward - android

The scenario is I am using Coordinator Layout having CollapsingToolbarLayout inside of AppBarLayout. I have a RecyclerView just below the AppBarLayout.
Now say, I have many items in RecyclerView so that would be a lot of scrolling.
When scrolling up, the CollapsingToolbar/Appbar it is working perfect(i.e. Scrolling up it hides), but when I scroll down on the RecyclerView the CollapsingToolbar/Appbar scrolls down first(hence it becomes visible again fully) NOT the items of RecyclerView which leads to less space for showing the RecyclerView items.
How could I just achieve a type of scrolling so that it could behave like the AppBarLayout and RecyclerView were inside of a LinearLayout(for instance), hence Appbarlayout show appear only when the Parent is at the TOP scrolling position and should not appear when scrolling is mid-way in the RecyclerView.
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|enterAlways|snap"
>
</CollapsingToolbarLayout>
</AppBarLayout>
<RecyclerView
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</RecyclerView>

It seems to have somehting to do with your scroll flags. You specified app:layout_scrollFlags="scroll|enterAlways|snap"
You should specify app:layout_scrollFlags="scroll|snap" in order to scroll the CollapsingToolbarLayout only once your recyclerview is fully scrolled.

Related

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?

SwipeRefreshLayout with CollapsibleToobarLayout not scrolling down after cancelling a refresh

I have a CoordinatorLayout which is used to collapse a toolbar.
The CoordinatorLayout has a parent of SwipeRefreshLayout
<SwipeRefreshLayout>
<CoordinatorLayout>
<AppBarLayout>
...
</AppBarLayout>
<NestedScrollView>
...
</NestedScrollView>
</CoordinatorLayout>
</SwipeRefreshLayout>
I followed this answer to get the swiping working with the SwipeRefreshLayout
https://stackoverflow.com/a/30785823
Yes I have seen people say put the refresh layout above the nested scroll, however for this use case I am looking to refresh both the nested layouts contents aswell as the appbar contents
However I have encountered a problem
When you go to swipe a refresh and are mid way through it so the refresh spinner is showing but the refresh has not been triggered, when you go to scroll back down, the screen will not scroll, instead the refresh spinner will be stuck there until you take your finger off the screen.
Here are the steps I took to produce this error:
Swipe down so the refresh spinner comes up but do not let go
Swipe back up as if you were going to scroll down the screen
Edit: I have seen this used before on the TradeMe app when you view an item however I cannot figure out how they have gone about it https://play.google.com/store/apps/details?id=nz.co.trademe.trademe&hl=en
Instead of CoordinatorLayout, try to capsulate only the NestedScrollView within SwipeRefreshLayout.
<CoordinatorLayout>
<AppBarLayout>
...
</AppBarLayout>
<SwipeRefreshLayout>
<NestedScrollView>
...
</NestedScrollView>
</<SwipeRefreshLayout>>
</CoordinatorLayout>

Collapse Layout inside ContraintLayout based on view focus or scroll

I am looking into CoordinatorLayout and ConstraintLayout and I want to know if it's possible to achieve something as in :
As you can see my layout, has:
the toolbar which is not affected by this. The toolbar is on the main activity and it's not changed.
under the toolbar there is a fragment loaded with its layout. The layout contains a ImageView at the top, some EditTexts and a RecyclerView
Behavior:
When user taps on the red EditText I want the layout to scroll up, so that the focused EditText is at the top of the screen with the RecyclerView under it.
At any time the user can scroll down and the initial layout gets shown.
My question is: what would be the best way to create this animation and behavior?
I managed to obtain the desired behavior by using in the layout:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<My layout that will get scrolled to the top and be hidden>
</CollapsingToolbarLayout>
<RedEditText which will scroll up until the CollapsingToolbar is collapsed>
</AppBarLayout>
<RecyclerView/>
</CoordinatorLayout>

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

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.

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.

Categories

Resources