最底

ScrollView当显示超出当前页面时自动移动到最底端

て烟熏妆下的殇ゞ 提交于 2019-12-03 20:10:19
卷轴视图(ScrollView)是指当拥有很多内容,一屏显示不完时,需要通过滚动来显示视图。比如在做一个阅读器的时候,文章很长,一页显示不完,那么就需要使用卷轴视图来滚动显示下一页。 private ScrollView mScrollView; private LinearLayout mLayout; private final Handler mHandler = new Handler(); mScrollView = (ScrollView)findViewById(R.id.scroll); mLayout = (LinearLayout)findViewById(R.id.linearlayout);//linearlayout外层为 scroll mHandler.post(mScrollToBottom); private Runnable mScrollToBottom = new Runnable() { @Override public void run() { // TODO Auto-generated method stub int off = mLayout.getMeasuredHeight() - mScrollView.getHeight(); if (off > 0) { mScrollView.scrollTo(0, off); } } }