zoukankan      html  css  js  c++  java
  • android 将ScrollView滚动到底部

    方案1:使用 scrollTo 或 smoothScrollTo 滚动到 scrollview 最后一个节点位置

    public static void scrollToBottom(final View scroll, final View inner) {
        Handler handler = new Handler();
        handler.post(new Runnable() {
            public void run() {
                int offset = inner.getMeasuredHeight() - scroll.getHeight();
                if (offset < 0) {
                    offset = 0;
                }
                scroll.scrollTo(0, offset);
            }
        });
    }

    方案2(如scrollview中元素还未加载完全就调用,滚动到底部会失败。推荐使用方案3):

    scrollView.post(new Runnable() {
        public void run() {
            scrollView.fullScroll(View.FOCUS_DOWN);
        }
    });

    方案3:

    scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            scrollView.post(new Runnable() {
                public void run() {
                    scrollView.fullScroll(View.FOCUS_DOWN);
                }
            });
        }
    });
  • 相关阅读:
    搜索框的创建
    自定义非等高 Cell
    自定义等高 Cell
    表格多选删除
    聊天布局
    表格编辑
    表格折叠
    tableView 的协议方法
    UITouch
    UIDevice
  • 原文地址:https://www.cnblogs.com/ice5/p/13909181.html
Copyright © 2011-2022 走看看