I am trying to learn about CollapsingToolbarLayout which has some value set to scrollFlags to control how the view within it will collapse. Can anybody clearly demarcate the difference between these flags:
scroll
enterAlways
exitsUntilCollapsed
enterAlwaysCollapsed
enterAlways
How do these work when we set these flags to both Toolbar and CollapsingToolbarLayout.
I've made a table to clear things up. Also wrote quite an informative blog post with an example code on GitHub :)
scroll
Scroll Up: the view becomes visible when the layout's been scrolled all the way up
Scroll Down: the view scrolls with the rest of the content like it's a part of it; will hide if the layout's height is bigger than the screen's one
enterAlways
Scroll Up: the view becomes visible on every scroll up action, even if there's still a lot of content to scroll up
Scroll Down: the view scrolls with the rest of the content like it's a part of it; will hide if the layout's height is bigger than the screen's one
enterAlwaysCollapsed
Scroll Up: the collapsed version of the view (e.g. Toolbar) becomes visible on every scroll up action, and it expands (e.g. Toolbar with an ImageView) only when scrolled all the way up
Scroll Down: the view collapses and then hides, if the layout's height is bigger than the screen's one
exitUntilCollapsed
Scroll Up: the view is always visible, provided its height is > 0 and the expanded version (e.g. Toolbar with an ImageView) will become visible when scrolled all the way up
Scroll Down: the view scrolls with the rest of the layout's content, but only till its collapsed state (hence - "exit until collapsed"), so in case of a Toolbar with a fixed height, it will always be visible on the top
snap
Scroll Up AND Down fast scrolls up or down based on how much of the view is visible - if more than 50% - the view will scroll down, showing itself, if less - the view will hide; used with other flags as a further customization
From Antonio Leiva's blog here, the flags work like this:
scroll: This means it will scroll while scrolling the targeted view (our recycler view in this case).
enterAlways: When we scroll up, the view will immediately reappear.
enterAlwaysCollapsed: if the view has a collapsed mode, it will reappear collapsed when scrolling up.
exitUntilCollapsed: it won´t exit from the screen until the view is collapsed.
Related
I would like to scroll to the certain view when it becomes in focus.
I thought I could use onNestedScroll but the problem is that it takes only the distance to scroll, not the absolute scroll value.
So, I can get where the view is using getLocationInWindow but I don't know how to get the Y scroll of the entire layout. I tried to use AppBarLayout current offset, but it only shows the scroll on the collapsing toolbar.
I have a RecyclerView holding TextViews in its rows. When you scroll all the way down, the scrolling stops so that the last item's bottom is aligned with the RecyclerView's bottom. Is there an easy way to make the last item able to scroll so that it's top is aligned with the RecyclerView's top?
This is a screenshot of default behavior when scrolling all the way down:
This is the desired behavior:
What I have tried:
I have calculated the heights of all the other views besides the RecyclerView and subtracted this value from the dynamic screen height and added this value to the bottom padding of the last item in the RecyclerView. But for some reason the dimensions are pushing the last item out of view.
The heights I measured are:
status bar height, the app bar height, the 3 header heights, the bottom footer bar height, the bottom navigation bar height (not seen in screenshot), and the height of the last item itself
I have looked at other similar questions/answers (e.g. scroll recyclerview item to top inside of scroll view, Allow Recyclerview Items to scroll past top of Recyclerview, Android what does the clipToPadding Attribute do?) but no success.
I need it to work in both portrait and landscape mode.
I have an horizontal carousel that is embedded in a vertical scrollview.
I want to resize the content of the carousel once the user scrolls, so that the content will be collapsed when the user scrolls, and expanded when the user returns to the top (similar to what happens on material toolbar)
I know how to resize the carousel, but I'm not sure on how to notify the carousel views the new height, so that they can adapt their content to the new height.
Is there an standard way to do this?
My first thoughts are:
1) Make the carousel's height static, and change it on scroll. Then have the views implement onLayoutChangeListener or onSizeChange to make the change.
2) Make the carousel's height wrap_content (as it is now), and send the scroll event directly to the carousel views so that they change their own height (I'm not sure on how to do this)
Is there a way to move the AppBar up or down, based of percentage of view collapsable view visible when the scroll ends. In the CheeseSquare app, the Toolbar can get stuck in between when scroll ends.
Thanks
That's the exact use case of SCROLL_FLAG_SNAP:
Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to it's closest edge. For example, if the view only has it's bottom 25% displayed, it will be scrolled off screen completely. Conversely, if it's bottom 75% is visible then it will be scrolled fully into view.
Which was added in version 23.1 of the Android Support Library.
You can also use it via XML:
<android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways|snap" />
I have a ScrollView that I am trying to use to replicate the accepted behavior of a text messaging app. When the ScrollView is first loaded, I scroll to the bottom. And when the soft keyboard is brought up, the ScrollView adjusts its height to compensate. But when the height of the ScrollView is reduced, the bottom contents are hidden, instead of the top contents. I would like for the contents to be pushed up as the size is reduced.
Now I could scroll to the bottom as soon as the ScrollView is re-sized, but what if the ScrollView is not already scrolled to the bottom? Essentially, I want to keep the last visible text message that the user is looking at visible, regardless if it is at the bottom of the ScrollView or not.
I've also tried using the ADJUST_PAN layout parameter, but I don't want my whole window panned up. But if there is an analogous ScrollView behavior, that is exactly what I'm looking for.