RecyclerView跳转到指定位置,RecyclerView上下滑动监听,RecyclerView滑动速度

1、RecyclerView跳转到指定位置

只需调用recycleview的置顶方法:

recyclerView.scrollToPosition(15);

如果你需要让第15item在屏幕居中,只需吧scrollToPosition参数变小即可:

如:

recyclerView.scrollToPosition(12);或

recyclerView.scrollToPosition(9);

即可让15item在屏幕居中

 

注:置顶显示item

mRecyclerView.smoothScrollToPosition(currentIndex);

 

RecyclerView.canScrollVertically(1)的值表示是否能向下滚动,false表示已经滚动到底部
RecyclerView.canScrollVertically(-1)的值表示是否能向上滚动,false表示已经滚动到顶部

 

 

2、RecyclerView上下滑动监听——上拉刷新列表
 

private int lastposion, pagenum = 1, pageContent, num;
gxwbrecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {//用来标记是否正在向最后一个滑动,既是否向右滑动或向下滑动boolean isSlidingToLast = false;@Overridepublic void onScrollStateChanged(RecyclerView recyclerView, int newState) {LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();// 当不滚动时if (newState == RecyclerView.SCROLL_STATE_IDLE) {//获取最后一个完全显示的ItemPositionlastposion = manager.findLastCompletelyVisibleItemPosition();int totalItemCount = manager.getItemCount();if (lastposion == (totalItemCount - 1) && isSlidingToLast&&!ifload) {pagenum++;if (pagenum>pageContent){Toast.makeText(getContext(), "已到底!", Toast.LENGTH_SHORT).show();return;}getarealist(1);}}}@Overridepublic void onScrolled(RecyclerView recyclerView, int dx, int dy) {super.onScrolled(recyclerView, dx, dy);//dx用来判断横向滑动方向,dy用来判断纵向滑动方向//大于0表示,正在向右滚动;小于等于0 表示停止或向左滚动isSlidingToLast = dy > 0;}
});

 

 

void onScrollStateChanged(RecyclerView recyclerView, int newState): 滚动状态变化时回调
void onScrolled(RecyclerView recyclerView, int dx, int dy): 滚动时回调
/*** The RecyclerView is not currently scrolling.(静止没有滚动)*/
public static final int SCROLL_STATE_IDLE = 0;/*** The RecyclerView is currently being dragged by outside input such as user touch input.*(正在被外部拖拽,一般为用户正在用手指滚动)*/
public static final int SCROLL_STATE_DRAGGING = 1;/*** The RecyclerView is currently animating to a final position while not under outside control.*(自动滚动)*/
public static final int SCROLL_STATE_SETTLING = 2;

 

 

3、安卓手机7.0RecyclerView显示不全解决方法

解决办法是在RecyclerView的外部套上一层RelativeLayout

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/menuRv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_16"
            android:layout_marginRight="@dimen/margin_16"/>

</RelativeLayout>

Android ScrollView与RecyclerView滑动冲突问题

解决滑动冲突、滑动不流畅
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);

 

滑动速速设置

1、自定义类

public class LinearLayoutManagerWithScrollTop extends LinearLayoutManager {public LinearLayoutManagerWithScrollTop(Context context) {super(context);}public LinearLayoutManagerWithScrollTop(Context context, int orientation, boolean reverseLayout) {super(context, orientation, reverseLayout);}public LinearLayoutManagerWithScrollTop(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);}@Overridepublic void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {TopSnappedSmoothScroller topSnappedSmoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext());topSnappedSmoothScroller.setTargetPosition(position);startSmoothScroll(topSnappedSmoothScroller);}class TopSnappedSmoothScroller extends LinearSmoothScroller {public TopSnappedSmoothScroller(Context context) {super(context);}@Nullable@Overridepublic PointF computeScrollVectorForPosition(int targetPosition) {return LinearLayoutManagerWithScrollTop.this.computeScrollVectorForPosition(targetPosition);}/*** MILLISECONDS_PER_INCH 默认为25,及移动每英寸需要花费25ms,如果你要速度变快一点,就直接设置设置小一点,注意这里的单位是f*/protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {return 15f / displayMetrics.densityDpi;}@Overrideprotected int getVerticalSnapPreference() {return SNAP_TO_START;}}
}

2、引用即可

mRecyclerView.setLayoutManager(new LinearLayoutManagerWithScrollTop(this));

 

不可滑动

//        LinearLayoutManager layoutManager = new LinearLayoutManager(this) {
//            public boolean canScrollVertically() {
//                return false;
//            }
//        };LinearLayoutManager layoutManager = new LinearLayoutManager(this);layoutManager.setOrientation(RecyclerView.VERTICAL);recyclerView.setLayoutManager(layoutManager);

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415273.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

工作169:vue项目报错[Vue warn]: Property “visible“ must be accessed with “$data.visible“ because properties

vue项目中报错&#xff1a; [Vue warn]: Property "visible" must be accessed with "$data.visible" because properties starting with "$" or "_" are not proxied in the Vue instance to prevent conflicts with Vue internalsS…

Python 开篇及第一个Python程序

本节内容 python 简单介绍python 2.x 或者python 3.xpython 安装第一个python程序一、python简单介绍 python的创始人为吉多.范罗苏姆(Guido van Rossum)。1989年的圣诞节期间&#xff0c;吉多.范罗苏姆为了在阿姆斯特丹打发时间&#xff0c;决心开发一个新的脚本解释程序&…

cesium进行模型高度测量的代码片段

主要参考 https://sandcastle.cesium.com/index.html?srcPicking.html export function monitorMove() {const viewer window.viewer;const scene viewer.scene;const handler new Cesium.ScreenSpaceEventHandler(scene.canvas);let previousPickedEntity undefined;var…

工作171:阅读账号里面的新增调用接口操作

第一步 点击新增操作 第二步 找到当前组件下面的 add的方法 第三步 找到子组件下面的混入方法

recycleview 使用详解,添加头部尾部,混合item,侧滑菜单,跳转到指定位置,实现九宫格布局

添加头部尾部&#xff0c;混合item&#xff1a;https://blog.csdn.net/meixi_android/article/details/82256319 侧滑菜单&#xff1a;https://blog.csdn.net/meixi_android/article/details/82344439 实现九宫格布局&#xff1a;https://blog.csdn.net/meixi_android/articl…

PHP输入流 php://input 相关【转】

为什么xml_rpc服务端读取数据都是通过file_get_contents(‘php://input, ‘r)。而不是从$_POST中读取&#xff0c;正是因为xml_rpc数据规格是xml&#xff0c;它的Content-Type是text/xml。php://input碰到了multipart/form-data在使用xml-rpc的时候&#xff0c;server端获取cli…

js 全屏 退出全屏

直接上代码&#xff1a; 全屏 function fullScreen() {var el document.documentElement;var rfs el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;if(typeof rfs ! "undefined" && rfs) {rf…

Android java 中的问号与冒号? : 表达式,与%1$表达式

A&#xff1a;布尔表达式(真/假)&#xff0c;B&#xff1a;执行语句 &#xff0c;C &#xff1a;执行语句 最直观的&#xff1a; A &#xff1f; B &#xff1a;C (如果A为真执行B否则执行C) android中的一段代码 1 return mData ! null ? mData.size() : 0; 声明s代表连接…

浏览器跨域访问解决方案

浏览器跨域访问解决方案 2015年11月4日 18972次浏览跨域的概念 跨域大家都知道&#xff0c;不同地址&#xff0c;不同端口&#xff0c;不同级别&#xff0c;不同协议都会构成跨域。例如&#xff1a;about.haorooms.com和www.haorooms.com都会构成跨域。总结起来只要协议、域名、…

oracle 分页

我直接贴代码了&#xff0c;做一个备份 public async zbjhList(request: Hapi.Request, h: Hapi.ResponseToolkit) {const { page, size } request.payload;const min (page - 1) * size;const max page * size;let sql SELECT * FROM (SELECT ROWNUM AS rowno, t.* FROM …

Android 2017-2018面试题详解

面试题&#xff08;固定答案不解答&#xff0c;自己可以找到&#xff09; 顺序是根据记忆排的&#xff0c;没有优先级之分&#xff0c;都是重点。 1.Activity的启动过程&#xff08;不要回答生命周期&#xff09; http://blog.csdn.net/luoshengyang/article/details/6689748…

docker查看容器并运行

1、查看所有容器 docker ps -a结果 2、运行容器 docker start 56b90db5253e

IE8 select 动态下拉遇到的问题

发生背景:经QC测试程序一直没问题,到客户测试竟然出现了下拉窗口失效. 检查发现客户用的IE ,360 浏览器都出现一样的问题,据说360是引用IE的核心. 看下IE版本是 8的..... 开发和QC都是11版本的... 经过一阵和度娘互动找到了下面原因 1.IE8不支持 onchanged 事件. 解决:使用…

cesium 设置地球默认区域为中国 一键返回默认区域

直接上代码啦 Cesium.Camera.DEFAULT_VIEW_RECTANGLE Cesium.Rectangle.fromDegrees(90, -20, 110, 90); const viewer new Cesium.Viewer(cesiumContainer, { selectionIndicator: false,infoBox: false,animation: false,baseLayerPicker: false,timeline: false,geocoder…

Spring boot Tomcat配置

来自: https://www.cnblogs.com/a8457013/p/7687764.html转载于:https://www.cnblogs.com/eason-d/p/7884307.html

js 快捷键

直接上代码 document.onkeydown onKeyDown; function onKeyDown() {if (window.event.ctrlKey && (window.event.keyCode 69)) {alert("ctrle");} }键码值如下 字母和数字键的键码值(keyCode)按键键码按键键码按键键码按键键码A65J74S83149B66K75T84250C…