Overlap items in recyclerView - android

I have a RecyclerView with list of items displayed top to bottom.
I would like to have view of last item overlapping with the previous one.
I used RecyclerView.ItemDecoration with negative top margin and it almost does the trick. Item views indeed overlap, but when I'm at the bottom of the list and I start scrolling up then overlapping view disappears too early.
It looks like RecyclerView does not take into account the negative margin at all when deciding if item is visible or not.
Is there a way to fix that?
Thanks,

Related

How to make last item scroll all the way to the top of RecyclerView

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.

How do I clip recyclerView after first item decoration at the top

I have a pinned ItemDecoration (a header section) added before first (top) child of the RecyclerView.
When I scroll the RecyclerView, first item goes behind the header section. Since the section is transparent it looks like that section and first item get overlapped.
How can I clip the RecyclerView so that the overlapping does not happen?
I assume that your ItemDecoration is using DrawOver() for the sticky header. Try setting a top padding to the RecyclerView that has a height equal to the height of your header android:paddingTop="somedp" and set android:clipToPadding="true". See this Stack Overflow answer for a good description of clip to padding.
You may have to adjust how your item decoration is drawn but this should prevent your items from sliding under the header.

Scroll RecyclerView Scroll to position always on top

I'm using linear layout manager and RecyclerView with a LinearLayout Manager to populate some list of items. When I'm displaying the recyclerview for the first time and I use:
linearLayoutManager.scrollToPosition(desiredindex);
it scrolls to the top exactly where I want.
Now here is the tricky part - When I'm scrolling to top of recyclerview (i.e. new items indices will be lower than the desiredindex) and I call:
linearLayoutManager.scrollToPosition(desiredindex);
It still works fine, but when the recyclerview has been scrolled beyond the desiredindex, the recycler view scrolls such that the desiredindex item comes to the bottom rather than on top, but I want the tile to scroll to the top not the bottom.
Use scrollToPositionWithOffset like this:
linearLayoutManager.scrollToPositionWithOffset(desiredindex, 0);
scrolltopositionwithoffset(position, offset) forces the indicated item visible with indicated offset. The offset is distance from the top of RecyclerView.

How do I ensure that the last item in a RecyclerView is aligned to the bottom of the window when the list is not scrollable?

I want to ensure that the last item in my RecyclerView is aligned to the bottom of the window when the content isn't scrollable, like so:
aligned to bottom
I also need the last item to append to the bottom of the list and scroll with it if it is scrollable, like so:
scrolling with RecyclerView content
I am not necessarily looking for line-by-line code on how to do this. I am looking for the right approach. I have explored the option of using a separate "clone" view outside of the RecyclerView for the first case, but I want to keep the behaviour of a ReyclerView item so that didn't work out. Open to suggestions.

Recyclerview footer at bottom of screen when no scroll AND at end of the list when it has scroll

In my application I have branding footer at the end of scroll on all screens (for screens which have scroll) and static at bottom of the screen when(no scroll).
But I am facing issues to achieve this with screen which has list. I am using recyclerview for showing list. I want to show Branding Footer at end of the recyclerview when it has scroll and it will be visible when it is scrolled at the bottom. This is achievable with Recyclerview with footer.
But when recyclerview does not have scroll (when few items in list), I want footer fixed at bottom of the screen.
Thanks in advance!
The question appears similar to several other, most of the stack overflow posts related to this question point towards the usage of itemdecoration to achieve this (By adding itemdecoration of the desired height)
One way of achieving this would be to determine the height of the recycler view beforehand and then using that information to set the offset for the footer in the itemdecoration associated with the recycle view
This might help: How implement sticky footer in recyclerview

Categories

Resources