1,直接回到顶部

recyview.getLinearLayoutManager().scrollToPositionWithOffset(0, 0);

2,慢慢的回到顶部

private void goTop(int currentPoint) {
        if (currentPoint >= 0) {
            int step = 3;
            if (currentPoint % 10 > 1)
                step = 10;
            if (currentPoint % 5 > 1)
                step = 5;
            if (currentPoint - step > 0) {
                getView().getLinearLayoutManager().scrollToPositionWithOffset(currentPoint - step, 0);
            } else {
                getView().getLinearLayoutManager().scrollToPositionWithOffset(0, 0);
                return;
            }
            Message msg = Message.obtain();
            msg.obj = currentPoint - step;
            msg.what = WHAT_DELAYED_GO_TOP;
            goTopHandler.sendMessageDelayed(msg, 30);
        }
    }

private static int WHAT_DELAYED_GO_TOP = 212;

/**
     * 解决内存泄漏问题
     */
    private final static class GoTopHandler extends Handler {
        private SoftReference<IndexForumContentPresenter> softReference;

private GoTopHandler(IndexForumContentPresenter indexFragmentPresenter) {
            this.softReference = new SoftReference<>(indexFragmentPresenter);
        }

@Override
        public void handleMessage(Message msg) {
            // 作废重复调用
            if (this.softReference.get() == null)
                return;
            if (msg.what == WHAT_DELAYED_GO_TOP) { // 切换轮播
                // 回调给界面进行切换界面操作
                this.softReference.get().goTop((Integer) msg.obj);
            }
        }
    }
2.1慢慢的回到顶部:调用

int firstPosition = recyview.getLinearLayoutManager().findFirstVisibleItemPosition();
goTop(firstPosition);

Android RecyView 滑动置指定位置的更多相关文章

  1. RecyclerView滑动到指定位置,并置顶

    一般我们用 mRecycleview.smoothScrollToPosition(0)滑动到顶部,具有滚动效果,但是如果我们想滚动到任意指定位置,那么smoothScrollToPosition() ...

  2. Android 在图片的指定位置添加标记

    这些天,项目里加了一个功能效果,场景是: 假如有一个家居图片,图片里,有各样的家居用品: 桌子,毛巾,花瓶等等,需要在指定的商品处添加标记,方便用户直接看到商品,点击该标记,可以进入到商品详情页 .实 ...

  3. jquery实现点击按钮滑动到指定位置

    <body> <script type="text/javascript"> function click_scroll() { var scroll_of ...

  4. android学习——popupWindow 在指定位置上的显示

    先看效果图,免得浪费大家时间,看是不是想要的效果 . 直接上代码 ,核心方法. [java] view plaincopy private void showPopupWindow(View pare ...

  5. 鼠标滑动到指定位置时div固定在头部

    $(function(){ $(window).scroll(function () {            if ($(window).scrollTop() > 253) {       ...

  6. JQuery滑动到指定位置

    $('html, body').animate({ scrollTop: next_tip.offset().top + "px"},500);

  7. 横向滑动的HorizontalListView滑动指定位置的解决方法

    项目中用到了自定义横向滑动的控件:HorizontalListView,点击其中一项,跳转到另外一个大图界面,大图界面也是HorizontalListView,想使用setSelection方法设定 ...

  8. (转载) popupWindow 指定位置上的显示

    popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报  分 ...

  9. jQuery实现将div中滚动条滚动到指定位置的方法

    1.JS代码: onload = function () { //初始化 scrollToLocation(); }; function scrollToLocation() { var mainCo ...

随机推荐

  1. Contentprovider的创建和使用流程概述

    首先在provider类中继承并实现provider的几个必要方法 -- boolean onCreate(),用来执行一些初始化的工作. -- cursor query(Uri, String[], ...

  2. php get_include_path();是干嘛的、??还有set_include_path();/?????

    首先 我们来看这个全局变量:__FILE__ 它表示文件的完整路径(当然包括文件名在内) 也就是说它根据你文件所在的目录不同,有着不同的值:当然,当它用在包行文件中的时候,它的值是包含的路径: 然后: ...

  3. SpringBoot07 异常枚举、自定义异常、统一的全局异常处理

    1 异常编号和提示信息统一管理 利用枚举来实现异常的统一管理 package cn.xiangxu.springboottest.enums; import lombok.Getter; /** * ...

  4. EZOJ #87

    传送门 分析 由于我不知道壶里到底有多少水,那么显然我第一次 分别向两个杯子分别到 L/2 +1 和 L/2 才是最优的.(这样既维护了两个人的差值不超1,又正好倒了L的水).那么接下来如果壶里还有水 ...

  5. 1.初学c++,比较困惑的问题。

    1.c++是一门实用的语言吗? c++是一个实用的工具,它很有用. 在工业软件世界中,c++被视为坚实和成熟的主流工具.它具有广泛的行业支持和好批. 2.面向对象编程在c++中的作用? 我们要开发一个 ...

  6. python---pyspider,报错?

    conf.json文件内容如下: { "message_queue": "redis://127.0.0.1:6379/15", "webui&quo ...

  7. 浅谈assert()函数的用法

    #include<stdio.h> #include<assert.h> char * Strcpy(char *dst,const char *src) { assert(d ...

  8. Linux sogou input method

    afda@afda-Y720-15IKB:~$ wget "http://pinyin.sogou.com/linux/download.php?f=linux&bit=64&quo ...

  9. Java50道经典习题-程序25 根据输入求输出

    题目:一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同.分析:分别创建两个数用于判断,一个数为12321,另一个数是12341 分别取出该数的"个十百千万 ...

  10. python:格式化输出整数

    import math #default print "PI = %f" % math.pi #width = 10,precise = 3,align = left print ...