Current scroll position in CoordinatorLayout with CollapsingToolbarLayout - android

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.

Related

How to properly scroll nested-scrollview?

How to properly scroll to a position in nestedscrollview which is inside a coordinate layout? When I use scrollTo(), it seems like the view inside AppBarLayout is loosing the ability to scroll down when I scroll to the end of NestedScrollView and coming back to top. What I need to know is how to programtically scroll to a position in nestedscrollview without causing problem with the normal behavior of collapsing layout.
Issue is similar to what is mentioned in this post:
The Coordinator layout doesn't Scroll up for a specific position
There is a Gif attached along with the above question:
https://i.stack.imgur.com/uSGfX.gif
I have tried the solution in above link, but it is not working.

Image Zoom In and Out with Recycler View Android

I am trying to implement a Recycler View in which the first item covers at-least half of the screen. This item has an image set as a background.
The behavior that i want to achieve is: when user scrolls upward the recycler view, the image should zoom in, and when user scrolls it downward, the image should zoom out and should be in original dimension as soon as the first item is completely visible.
I have tried using setScale() property on imageView but it's not working as expected. Please help!
Keep the first item in CollapsingToolbarLayout instead of placing it in RecyclerView and wrap both the views in CoordinatorLayout.
Then in CollapsingToolbarLayout add parallax effect using attribute collapseMode="parallax"
Finally, bound the RecyclerView scroll behavior to CollapsingToolbarLayout using property layout_behavior="#string/appbar_scrolling_view_behavior".

recyclerview inside scroll view affects scroll position

I have the following layout structure
--FrameLayout
--scrollview
--LinearLayout
--LinearLayout
--RecyclerView
--LinearLayout
When I arrive at the page, it seems to scroll to the recycler view.
I just want scroll position to be at the top when arriving at the page.
Seems odd, When i switch the order between the linearlayoout and recyclerview inside the scrollview, then the behaviour is correct - as in the scroll position is at the top
This worked for me:
mRecyclerView.setFocusable(false);
Although a lot of good answers here: How to scroll to top of long ScrollView layout?

Difference between different scrollFlags for CollapsingToolbarLayout

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.

Set scroll range of Android ScrollView

I was wondering if it was possible to set the scroll range of the android ScrollView. Basically I have a scroll view with one child in it that extends 100 pixels past the bottom of the screen. Normally the scroll view will scroll till it gets to the bottom of the child view, is there a way to get the scroll view to stop scrolling like half way and not show the whole child view? I have tried extending ScrollView and overriding the computeVerticalScrollRange() but that did not work. Any help would be appreciated.
Thanks,
Sam
Do you want it to only sometimes scroll to the bottom? Or never at all? In the case of the latter, I would suggest reconsidering your layout and removing that child from the scrollview parent.

Categories

Resources