How to move the n-th invisible item of recyclerview to center - android

I'm using a recyclerView to support an item selection function for an android app, where each item of recyclerView will be a same sized image view. When creating the recyclerView, I already know that the n-th item is the selected one, how do I directly display the n-th item in center or just make it visible?
UPDATE:
So I achieved this by first calling linearLayout.scrollToPosition(n-th position) to make the item visible, then adding a addOnGlobalLayoutListener, which will wait for the layout to be complete, then calculate the offset and do a smooth scroll to center.

Use layoutManager.scrollToPositionWithOffset(n-th position, half width of screen).
It automatically scroll to n-th item position.

Related

Allow Recyclerview Items to scroll past top of Recyclerview

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

Scrolling an item to the top position is not working in RecyclerView for few items in the adapter

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.

Vertical ViewPagers(kind of) thing using a list(recyclerview or listview)

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.

Android scroll list programmatically with animation

I want to scroll a list view by x pixels
list.scrollListBy(x) works, but the default scrolling animations are missing
Is there any api to scroll list with animation,
I cannot use smoothScrollBy and its other varients, because it wont scroll if the element is already visible.
If you are using RecyclerView, you can call the method
list.scrollToPosition(int position)
to scroll to a particular position on the list. Let's say there are 50 positions on the list, and your phone screen is showing first 10 positions of the list. Then you can call
list.scrollToPosition(40);
to scroll to the 40th position. There will be a slightly smooth effect.

how to display listview's scroll item by item

i want to display the listview's scroll item by item, means single item height is equal to listview height, so on listview there is only one item will display at a time, and after scrolling the listview, remaining item will display. But problem is that if i scroll listview, it scroll many items, but i need to scroll only by one item.
in-short listview scroll by many row at a time but i want only one row scroll at a time
please suggest me some tips or method :)
thank you
So if I understand you correctly, you want a 'pager', sort of like, you scroll page per page instead of inbetween every item, right?
I'm using a Horizontal Pager at the moment, it uses a GroupView and measures the scroll amount to snap to the next view in the pager. Perhaps you could write your own GroupView as well calculating the scroll Y values to snap to the next page..
It's not going to be easy, but it's the only way I can think of.
You could look up Horizontal Pager on google and look at the code, and implement it for vertical paging :)

Categories

Resources