Skip to content
Advertisement

How to scroll one to one in recycler view?

this is my adapter

I want to scroll one item each time i scroll. Like when you see multiple images post on instagram. How can i do that?

Thanks

recyclerViewyeterr=findViewById(R.id.recyclerViewyeterr);

LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(GYUserSahaDetay.this, 
LinearLayoutManager.HORIZONTAL, false);

recyclerViewyeterr.setLayoutManager(horizontalLayoutManagaer);

gYresimadaptor=new GYresimadaptor(resimler2);

recyclerViewyeterr.setAdapter(gYresimadaptor);

and my XML;

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GYresimadaptor">

<ImageView
android:id="@+id/imageView33"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>

Advertisement

Answer

You can use a SnapHelper by attaching it to your RecyclerView with SnapHalper.attachToRecyclerView() and you will have a Scroll effect like instagram for example :

recyclerViewyeterr=findViewById(R.id.recyclerViewyeterr);

LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(GYUserSahaDetay.this, 
LinearLayoutManager.HORIZONTAL, false);

recyclerViewyeterr.setLayoutManager(horizontalLayoutManagaer);

gYresimadaptor=new GYresimadaptor(resimler2);

recyclerViewyeterr.setAdapter(gYresimadaptor);

SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerViewyeterr);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement