As we know we have option ListView.TRANSCRIPT_MODE_ALWAYS SCROLL which will scroll to bottom.
The list will automatically scroll to the bottom, no matter what items
are currently visible.
Now we are having RecyclerView, does there any similar option of this in RecyclerView?
You can use
recycler_view.scrollToPosition(int position);
where position is index of row in recycle view.
Related
So I have a horizontal recyclerview that can be scrolled both left and right (around 50 items in it). When the selected item in the recycler view is out of viewport, because I scrolled right, I want to change the background of the most right item, as an indicator that selected item is on the right, and same if I scroll left.
Not sure if I could use findLastCompletelyVisibleItemPosition(), because how would I get the position of the right/left most item?
to get the right most item, you can use findLastCompletelyVisibleItemPosition() and to get the left most item, you can use findFirstCompletelyVisibleItemPosition()
I have a RecyclerView list, in which I want the currently selected item to be shown at the top of the RecyclerView. I still however, want the entire list to be scrollable, therefore, removing views from above the selected item is not a possible solution.
It seems I need a mechanism where the RecyclerView items are able to scroll beyond the bounds of the RecyclerView. I'm not sure if this is possible, so if it is not, does anyone have a solution to ensuring the currently selected item scrolls to the top of the RecyclerView.
I have tried smoothScrollToPosition() but this doesn't work in the case of being at the bottom of the RecyclerView, and wanting one of the middle items to scroll to the top.
Many thanks
to Illustrate, I have a list of 4 items, the recyclerview cannot scroll as there is not enough items in the list.
Then I select an item
I then want the selected item to scroll to top, but for the item above to still be scrollable.
So, when I scroll up...
On the RecyclerView set a bottom padding that is equal to three times your item's height then set android:clipToPadding="false". This will let your bottom item scroll to the top and show the padding on the bottom item but only on the bottom item.
Here is an answer to a similar question that lays this technique out rather well.
lets assume that you have item on click listener for your recycler view, when user clicks on any item you get item position and view, below code is working for me
RecycleClick.addTo(firstRecyclerView).setOnItemClickListener(new RecycleClick.OnItemClickListener() {
#Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// YOUR CODE
int offset = position - yourRecyclerViewLayoutManager.findFirstVisibleItemPosition();
if (yourRecyclerViewLayoutManager.findFirstVisibleItemPosition() > 0) offset -= 1;
yourRecyclerViewLayoutManager.scrollToPositionWithOffset(position, offset);
}
});
make sure your layout manager comes from support library like this
android.support.v7.widget.LinearLayoutManager
otherwise you will not find findFirstVisibleItemPosition() method etc
I want to scroll a specific item to the top in RecyclerView.
Here is the code I am using,
rvTweets.smoothScrollToPosition(position);
or
linearLayoutManager.scrollToPositionWithOffset(postion,0);
Both the code work when RecycelerView has enough items to cover the complete height of the screen. Otherwise, it does not scroll the desired position to the top.
I made header and footer in my RecyclerView using typical solution with viewType in Adapter. It works fine, but I want to hide the footer if all RV items fit inside the screen, when nothing to scroll. Is there any way to know that all items will be displayed without scrolling and say to Adapter not to add footer in this case?
You can get scroll offset of recycler view with this code
recyclerView.computeVerticalScrollOffset();
Then you should check if scroll offset is more than your parent views heigh and do what you want ;)
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.