zoukankan      html  css  js  c++  java
  • Android RecyView 滑动置指定位置

    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);

  • 相关阅读:
    POJ3977 Subset 折半枚举
    Ubuntu和Win7双系统,ubuntu被删,重新启动之后显示,no such partition
    hdu 4296 贪心
    Python标准库:内置函数tuple([iterable])
    【python自制】让大白成为你的个人助手!
    Flex设置LinkButton的背景色
    VB6基本数据库应用(五):数据的查找与筛选
    正态分布(normal distribution)与偏态分布(skewed distribution)
    windows 系统文件 —— 特殊文件及文件类型
    windows 系统文件 —— 特殊文件及文件类型
  • 原文地址:https://www.cnblogs.com/wf-l5201314/p/9371280.html
Copyright © 2011-2022 走看看