I am trying to figure out how to have CoordinatorLayout scrolling range to be not screen height. My layout structure is following:
CoordinatorLayout
-- AppBarLayout
---- CollapsingToolbarLayout (scrollflags: scroll)
------ Toolbar (CollapseMode: parallax)
----- /CollapsingToolbarLayout
-- /AppBarLayout
-- NestedScrollView (Behaviour: appbar_scrolling_view_behavior)
-- /NestedScrollView
/ CoordinatorLayout
Even when NestedScrollView child height is like 100dp it can be scrolled all the way top when the content should not be scrollable at all.
Is there a way to affect the scroll range of CoordinatorLayout that if the child content is scrollable it will scroll and only the range that the height is.
I am also seeing this issue when child is RecyclerView and it has e.g. 1 50dp height child -> it should not scroll at all in this case, but when child count gets bigger it should then scroll.
Thanks.
Using AppBarLayout.ScrollingViewBehavior from below link fixes the issue with NestedScrollView
https://github.com/natario1/ConstrainedScrollBehavior/blob/master/ConstrainedScrollBehavior.java
I think as long as there's a scroll behavior in the layout and collapsingtoolbar has a scroll flag, it always can be scroll.
but you can try this trick to disable the scroll
How to disable CollapsingToolbar's collapse when scroll has not content?
Related
I want to make the NestedScrollView children visible when scrolled beyond the NestedScrollView Bounds so if that is possible can any one help it with me?
Like This -->
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.
My layout is ConstraintLayout and hierarchy is like this:
There is top view area that takes half of the screen, below that a TabLayout and ViewPager. In this ViewPager there are 3 tabs which contain a RecyclerView. When any RecyclerView is scrolled, top area collapses to 10% of height and ViewPager expands. Due to this RecyclerView expands too. However, after this expansion, RecyclerView items stars overlapping too.
What could be the cause of this?
If you use the ConstraintLayout and enable animation for each item when has changed. Let disable that issue will be resolved.
android:animateLayoutChanges="false"
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.
I need to be able to make a bi-directional RecyclerView. Basically, it would scroll vertically, but each row would be a horizontal list of tiles that could scroll. The initial scroll position would be at the top and left. The user could scroll down, and scroll to the right with each row.
Any ideas on how to do this? (e.g. with a custom LayoutManager or touch event interception).
I was able to solve the issue using a custom view implementation.
At the root, I have a custom ScrollView; when onMeasure is called, the ScrollView tells its children how tall they should. In this case, they are half the height of the ScrollView. The width matches the height so they display as square tiles.
Each of the ScrollView children are RecyclerView's with a horizontal LinearLayoutManager. Since the ScrollView tells each child how tall to be, there's no issues with measurement and they actually scroll very well in both directions (vertically and horizontally).