I have a recyclerView with multiple viewTypes, is there any way using which I can stick a particular viewType on top of the recyclerView once it reaches there after getting scrolled up?
This viewHolder initially appears at the bottom but once user scrolls up and the view reaches on top I want it to stick there and on scroll down naturally comes down to original position.
Related
I am building an app for Android TV by using Nested RecyclerView. Root is vertical RecyclerView which has rows with Horizontal RecyclerView.
I want to change the focus on the single click and want to keep the scroll position static. But scrolling is always happening at the bottom of the view for horizontal and vertical both.
I am using the focus listener to scroll to top
verticalRLVLayout.scrollToPositionWithOffset(rowNumber,0);
horizantalRLVLayout.scrollToPositionWithOffset(columnNumber, 0);
This is not working always and i don't see this is the best option.
Is there any way by which if we have fixed height of each row the single click will change the focus always.
Going upward in the RecyclerView, causes new row to slide towards right and focus goes to last visible tile on the previous row. Why this is happening, any idea ?
Thanks
I am developing an app that has a recyclerview, where a view needs to be at the top depending on the current time. I did a lot of research on how to leave a view at the top, however, the solution found (scrollToPositionWithOffset) just leaves that view visible, and not necessarily at the top. I need this view to always be at the top, even when the number of views is less than the height of the recyclerview or the top view is the last (with views prior to it). In such cases, the previous views would be visible only if scrolled up.
For example:
As can be seen, each view is ordered by time, so I can't just insert a view in the first position. In addition, there are times when the visible part of the recyclerview will be smaller than its size, even if there are items before the top view, so the scroll methods do not work here, since they only scroll until the view is visible, and not until it gets to the top. I am implementing this list with Recyclerview and LinearLayoutManager
I have a list of elements in a recycler view that are generated dynamically using data binding. Each element has a bottom view that is initially set to View.GONE, however once a user clicks the element and the view is expanded, the recycler view automatically scrolls back to the top of the list. Conversely, if the view is expanded and then clicked again to collapse, the recycler view scrolls to the top of the list again. I have tried keeping track of the ID's of the elements for the adapter (again using data binding), setting focus to the child element when they expand or collapse, and using binding adapters to animate the expand/collapse itself.
My suspicion is that the adapter in the recycler view is receiving a onNotifyDataChanged() alert when the height of one of the child changes, rendering an additional view (still inside one of the children though, not a separate child in the list), and automatically scrolls to the top. Is there a way to override this? Does anyone know what else might be causing the list to snap to the top when one of the elements is clicked -> expanded/collapsed?
So I found the solution to my issue in case someone encounters something similar. I actually ended up finding this answer: RecyclerView notifyDataSetChanged scrolls to top position
and the second solution involving the staggered layout manager was the route I went with, since I want to be able to wrap the content. My suspicions were correct that it had to do with the changing height of the elements in the recycler view. The expandable item's parent wrapped content, so the recycler view was forced to recalculate the size of the item once the expandable portion appeared/disappeared (at least that's what I got out of it).
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.
What I want to achieve is that when the list is populated in recyclerview, every list item when scrolled up or down should be displayed as one item in the list only(covering whole of the space provided for the recyclerview). In other word, lets say that each list item should match the height and width of recyclerview. When the list is scrolled all the big listitems can be seen scolling but when scrolling ends only one view is displayed.
If still not clear, I just want a recyclerview to show only one item at a time and if we want to see other list items we have to scroll.
Similar to what a view pager but vertical in direction and should be using a recyclerview.