Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Recyclerview水平滚动,如何在滚动式寻呼机上显示一个项目_Android_Android Viewpager_Android Recyclerview - Fatal编程技术网

Android Recyclerview水平滚动,如何在滚动式寻呼机上显示一个项目

Android Recyclerview水平滚动,如何在滚动式寻呼机上显示一个项目,android,android-viewpager,android-recyclerview,Android,Android Viewpager,Android Recyclerview,我必须使用recyclerView实现垂直和水平滚动,实际上,我可以通过使用LinearLayoutManager设置方向来更改recyclerView的方向。问题是水平滚动在同一页面中显示下一个项目时,我应该一次只显示一个项目,而滚动应该显示下一个项目请帮我解决这个问题或任何建议 **main.xml** <LinearLayout android:id="@+id/recyler_container" android:layout_width="match_paren

我必须使用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"/>
**main.xml**


如果希望RecyclerView模仿ViewPager的行为--


那么使用
ViewPager
有什么问题?@向导没有问题,但我正在单列列表中处理这个问题。因此,如果它是RecyclerView,那就太好了。因为我已经用垂直视图实现了recyclerView中的所有功能。这可能不保证有一个完整的答案,所以我建议您和任何有类似问题的人:另一个选择是只使用ViewPager2,它基于RecyclerView,但也具有ViewPager功能。如何将其归档到垂直滚动的RecyclerView(一次只显示一行)?@kavie将LinearLayoutManager.HORIZONTAL更改为LinearLayoutManager.Vertical如何做到这一点,但屏幕上只有n个数字?效果非常好
**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>
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);