Recyclerview Horizontal scroll,How to display one item at a scroll like pager(Recyclerview水平滚动,如何像寻呼机一样在滚动中显示一个项目)
问题描述
我必须使用 recyclerView 实现垂直和水平滚动,实际上我可以通过使用 LinearLayoutManager 设置方向来更改 recyclerview 方向.问题是当水平滚动显示同一页面中的下一个项目时.我应该只显示一个当我们滚动时项目应该显示下一个项目请帮助我解决这个问题或任何建议.
**main.xml**<线性布局android:id="@+id/recyler_container"android:layout_width="match_parent"安卓:layout_weight="1"android:layout_height="0dp"> 解决方案 如果你想让 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);
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>
解决方案 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);
这篇关于Recyclerview水平滚动,如何像寻呼机一样在滚动中显示一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Recyclerview水平滚动,如何像寻呼机一样在滚动中显示一个项目
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
