有两种方式:
第一种:chatScroll为scollView控件对象
chatScroll.post(new Runnable() {
public void run() {
chatScroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
第二种:
/**
* 将ScollView 移动到最底端
* @param scroll ScollView
* @param inner ScollView里面一层控件的View
* @param moreHeight 多余的高度
*/
public static void scrollToBottom(final View scroll, final View inner ,final int moreHeight) {
Handler mHandler = new Handler();
mHandler.post(new Runnable() {
public void run() {
if (scroll == null || inner == null) {
return;
}
int offset = inner.getMeasuredHeight() - scroll.getHeight()
+ moreHeight;
if (offset < 0) {
offset = 0;
}
scroll.scrollTo(0, offset);
}
});
}