I'm using a horizontal RecyclerView with PagerSnapHelper to make it look like a ViewPager. It's displaying child views.
How can I make it show a small peek of the next entry? The user needs to see close to 20% of the next entry to understand intuitively that they need to swipe horizontally. The earlier entry needs to align back.
There could be other indications of dots at the bottom but this is the expected behaviour. The child view occupies the entire recycler view, so adjusting the width of the child so as to make other siblings come onto the screen isn't an option.
Right now I'm using a RecyclerView that is set up with a PagerSnapHelper.
I'm able to scroll to 20% of the next entry by using this:
val nextPosition = (currentPosition + 1) % numOfEntries
val xscrollDistance = carouselRecyclerView.width * 0.80
linearLayoutManager.scrollToPositionWithOffset(nextPosition, xscrollDistance.toInt())
With this, I see the next entry come onto the screen like a peek but here's what I'm unhappy with:
This scroll isn't smooth, I'm looking for a smooth scroll to the 20% peek of the next entry
Snap doesn't work. I was hoping when I do step 1., the snap behaviour will kick in and align the earlier entry onto the screen. It doesn't happen that way.
The peeking behaviour also needs to be cyclic. Last entry's peek should be the 0th entry.
I'm also looking for a less complex solution if any.
I checked an older solution - How to peek RecyclerView + PagerSnapHelper but I'm hoping to find a cleaner solution instead.
Related
I'm trying to make the items within a RecyclerView scroll along a path, specifically a curve. At the left and right edge of the screen the offset is 0, and in the middle of the screen the offset is 100% for example. I am attempting to achieve this by setting the Y translation of each view. Currently I am doing this in an OnScrollListener attached to the RecyclerView. This mostly works OK, but there are occasions where the OnScrollListener isn't invoked so the translation resets to 0. These occasions include when adding or removing an item from the RecyclerViews adapter.
Is there a better place to attempt to achieve this effect? I have also looked into using my own LayoutManager and overriding OnLayoutChildren, but again this doesn't work in all cases and isn't called when scrolling.
I want to be able to scroll a RecyclerView behind a keyboard. The issue is that if I have say more than 5 items in the RecyclerView.Adapter, and assume that each item might have a height of say 100dp. I want to be able to scroll the RecyclerView down with the keyboard still up and be able to scroll down to be able to see the first item in the RecyclerView.
In iOS you can set something called a contentInset on a NSTableView and that gives you extra scrolling space below the list. I am looking for something similar for the RecyclerView so far, there isn't much to go on.
INITIAL STARTING POINT
WHAT HAPPENS (Can't scroll down anymore)
WHAT I WANT (be able to scroll down)
I have a long list with a big header and footer and I need to scroll the list all the way down and show the whole footer.
Also, items can have very different height so the overall height cannot be simply calculated height * no items.
All the existing questions I've seen do not take in account the footer might be big and not entirely shown when scrolling to last position.
So far I've tried:
1) the simplest solution:
lv.setSelection(lv.getCount() - 1);
However this will not show the whole footer, only part of it and I need to have it all visible.
2) using:
requestFocus();
on the footer, the main layout in it, and any elements in the footer: this changes the focus but doesn't force the listview to scroll down.
3) using:
lv.scrollTo(x, y);
problem with this is that I couldn't get the real height of the listview in a reliable way as items are not fixed size.
Beside, after scrolling often part of the list is not shown leaving a wide white area.
4) header and footer are contained in two adapters but I couldn't figure out how to reach them to be shown on the screen
5) I have also tried a mixed approach:
lv.setSelection(lv.getCount() - 1);
lv.scrollListBy(mFooter.getHeight());
But the scrollListBy() doesn't seem to have any effects after a setSelection - not sure why.
Does anyone have any suggestions?
Thanks in advance
I'm using layout_scrollFlags="scroll|enterAlwaysCollapsed" with a toolbar minHeight of 0dip, with the intention of only bringing back the Toolbar when my first visible item in the RecyclerView is visible (as opposed to enterAlways, which brings it back immediately whenever the RecyclerView is scrolled up). However, the toolbar is never showing again after I scroll it off the screen. What am I missing?
Please take a look at the design support library sample app: cheesesquare
The proper way to implement your described behavior is to just use the scroll flag by itself:
layout_scrollFlags="scroll"
Hard to say without seeing your code, as a guess this could be one of two things:
1.
It seems there is a bug with this, the view disappears from the screen when set with a min-height greater than zero.Then returns min height when scroll down begins, and full height when the scroll reaches the top.
I think that your min-height of zero may be interfering with your return. As if the scrollview vanishes with a non zero min height, who knows what is going on to cause that, the zero min height may make it impossible to return with this bug.
Have a look at this video found here http://inthecheesefactory.com/blog/android-design-support-library-codelab/en half way down the page.
I quote from this page:
enterAlwaysCollapsed - This flag defines how View enter back into the
screen. When your view has declared a minHeight and you use this flag,
your View will only enter at its minimum height (i.e., ‘collapsed’),
only re-expanding to its full height when the scrolling view has
reached it’s top. Use it with scroll flag like this:
scroll|enterAlwaysCollapsed
Anyway it seems like it doesn't work as described in minHeight part.
I added emphasis.
2.
You have not formatted your code correctly.
From Android's Developer Blog I quote on "CoordinatorLayout and the app bar":
One note: all views using the scroll flag must be declared before
views that do not use the flag. This ensures that all views exit from
the top, leaving the fixed elements behind.
This link also goes into more detail about how to use enterAlwaysCollapsed and is worth looking at.
Let me know if this solves your problem.
I'm experimenting to see if the layout scheme I want to use is possible. I want to have an XML layout that's scrollable. Within that scrollable layout, I want to have a single line going horizontally across the screen (I used just a View with a fixed height and different color). When that horizontal line reaches the top of the screen, and as I scroll down through the layout, I want it to stop and remain at the top of the screen while being able to scroll through everything below it.
I've been messing around in XML trying to get it to work, basically putting a bunch of junk before it and after it.
Any ideas as to how that might work? Would I have to do something fancy with the java code to fix the red line at the top when the scroll position reaches a certain point? Your help would be greatly appreciated.
I am assuming you want something like Gmail app where when you scroll a mail the header sticks on top... To do this, you need 2 views. You have your regular scroller below and overlay a fixed view on top (you can use a relative layout to do this). When your cell goes past a certain spot, you want to populate and set the visibility of the fixed view to VISIBLE. This would give the impression that the view you want to 'stick' to the top really just got stuck rather than scrolled out of view. You'll have to work out the opposite scrolling scenario too based on the location and height of the scrolled cell/view.
HTH