android - Recyclerview水平滚动,如何像寻呼机一样滚动显示一个项目

标签 android android-viewpager android-recyclerview

我必须使用 recyclerView 实现垂直和水平滚动,并且实用地我可以通过使用 LinearLayoutManager 设置方向来更改 recyclerview 方向。问题是当水平滚动显示同一页面中的下一个项目时。我应该只显示一个当我们滚动时应该显示下一个项目,请帮助我解决这个问题或任何建议。

**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

最佳答案

如果你想让 RecyclerView 模仿 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);

关于android - Recyclerview水平滚动,如何像寻呼机一样滚动显示一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43024818/

相关文章:

java - 从 ArrayList HashMap<String, String> 中的键/值中检索值

android - 如何获取我所在的页面的编号? ViewPager 响应 native

android - recyclerview 中的重叠位置/ View

android - 如何在 RecyclerView 中保留 ViewPager 状态?

java - Firebase : Can't convert object of type java. lang.String 键入 com.example.positivethinkers.Members

android - 提交后折叠搜索 View

android - 导出 Facebook 好友电子邮件地址 Android

android - IntelliJ Android 无法附加调试器

android - 如何反转 viewpager 滑动

android - 未触发 ViewPager 上的 onClick