网络收集
((ScrollView)findViewById(R.id.scrollView1)).scrollTo(2, 2);
使用 scrollTo()方法时, 必须是在所有控件都加载完成 之后再,再调用此方法
在使用ScrollView的scrollTo方法的方法时候总是不能成功。
后来发现如果需要使用这个方法必须在ScrollView中post方法是用。
自动定位到顶部:
比如:
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
另外可以用另外一种方法:
public void scrollToBottom(final View scroll, final View inner) {
Handler mHandler = new Handler();
mHandler.post(new Runnable() {
public void run() {
if (scroll == null || inner == null) {
return;
}
int offset = inner.getMeasuredHeight() - scroll.getHeight();
if (offset < 0) {
offset = 0;
}
scroll.scrollTo(0, offset);
}
});
}
ScrollView 的滚动条默认置顶,若想设置它的位置,可以使用
mScrollView.smoothScrollTo(x,y)方法,可达到效果。
本人在开发过程中发现,使用mScrollView.scrollTo(x,y)方法,首次初始化时无效果,
改用 mScrollView.smoothScrollTo(x,y)则成功了!
注意:mScrollView.scrollTo(x,y) 方法不太好用的原因是:据资料说ScrollTo方法设置滚动的位置,将会调用 onScrollChanged(int,int ,int,int)方法,视图被视为无效。