Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview Horizontal scroll,How to display one item at a scroll like pager

Tags:

I have to implement both vertical and horizontal scroll using recyclerView and pragmatically I can change the recyclerview orientation by using LinearLayoutManager to set the orientation.The problem is when Horizontal scroll its showing next item in the same page.I should only show one item at a time when we scroll should display next Item please help me to fix this or any suggetion.

**main.xml**  <LinearLayout     android:id="@+id/recyler_container"     android:layout_width="match_parent"     android:layout_weight="1"     android:layout_height="0dp"> <android.support.v7.widget.RecyclerView     android:id="@+id/vertical_recycler_view"     android:layout_below="@id/slelect_scroll"     android:background="#fff"     android:layout_width="match_parent" android:layout_height="wrap_content"/> 

**row.xml**  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:orientation="horizontal"      android:layout_width="match_parent"      android:background="#3e56ed"      android:layout_height="wrap_content">   <TextView     android:textColor="#FFF"     android:textSize="18sp"     android:padding="16dp"     android:id="@+id/txtView"     android:text="sample text"     android:layout_weight="1"     android:layout_alignParentLeft="true"     android:layout_width="wrap_content"     android:layout_height="wrap_content" />  <TextView     android:id="@+id/txtView2"     android:textColor="#FFF"     android:textSize="18sp"     android:padding="16dp"     android:layout_marginLeft="20dp"     android:layout_weight=".1"     android:background="#000"     android:layout_alignParentRight="true"     android:text="sample text234"     android:layout_width="wrap_content"     android:layout_height="wrap_content" /> </LinearLayout> 

Verical SCroll

Horizontal scroll

like image 532
ASKAR ALI Avatar asked Mar 26 '17 03:03

ASKAR ALI


People also ask

How do I use SnapHelper in RecyclerView?

You can now just use a SnapHelper. If you want a center-aligned snapping behavior similar to ViewPager then use PagerSnapHelper: SnapHelper snapHelper = new PagerSnapHelper(); snapHelper. attachToRecyclerView(recyclerView);

Can you display a scrolling list of items in a RecyclerView?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .


1 Answers

If you want RecyclerView to mimic the behavior of ViewPager --

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);  LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false); SnapHelper snapHelper = new PagerSnapHelper(); recyclerView.setLayoutManager(layoutManager); snapHelper.attachToRecyclerView(mRecyclerView); 
like image 166
Connecting life with Android Avatar answered Oct 15 '22 02:10

Connecting life with Android