I have Achieved a similar requirement by using an RecyclerView with horizontal linear layout manager
here are the code snippets which may help you
To make the Recycler View appear horizontal use a LinearLayout manager and set its orientation to horizontal
mLinearLayoutManager = new LinearLayoutManager(context);
mLinearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
To make It circular: In your Recycler View adapter make the getItemCount to return a very large value like Integer.MAX_VALUE
.
@Override
public int getItemCount() {
return Integer.MAX_VALUE;
}
To get the actual item inside your adapter you can use simple modulus operation like this
@Override
public void onBindViewHolder(ActionItemViewHolder holder, int position) {
position = position % ACTUAL_SIZE_OF_LIST;
};
Here is the trick to makes it circular!
Make your RecyclerView to scroll to an index which is half of the value returned by your adapters getItemCount,You can achieve this by the below code:
mLinearLayoutManager.scrollToPosition(Integer.MAX_VALUE / 2);
(this is a simple hack)
I didn't understand what exactly you meant by auto Scrolling ,if you want the items to scroll to center of the screen on clicking it here is the code
private void scrollToCenter(View v) {
int itemToScroll = mRecyclerView.getChildPosition(v);
int centerOfScreen = mRecyclerView.getWidth() / 2 - v.getWidth() / 2;
mLayoutManager.scrollToPositionWithOffset(itemToScroll, centerOfScreen);
}
Hope this helps you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…