当前位置: 首页 > 知识库问答 >
问题:

如何在回收器视图中一对一滚动?

席波娃
2023-03-14

这是我的适配器

我想每次滚动一个项目。比如你在Instagram上看到多张照片。我怎么能那样做?

谢谢

recyclerViewyeterr=findViewById(R.id.recyclerViewyeterr);

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

recyclerViewyeterr.setLayoutManager(horizontalLayoutManagaer);

gYresimadaptor=new GYresimadaptor(resimler2);

recyclerViewyeterr.setAdapter(gYresimadaptor);

和我的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>

共有1个答案

宿镜
2023-03-14

通过使用snaphalper.AttachToRecyclerView()将其附加到您的RecyclerView,可以使用SnapHelper。例如:

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);
 类似资料: