1、 獲得ScrollView對(duì)象和ScrollView中包含的布局對(duì)象
mScrollView = (ScrollView) findViewById(R.id.l_rp_ques_main_scrollview);
mLayout = (LinearLayout) findViewById(R.id.l_rp_ques_main_scrolllayout);
2、在主線程定義一個(gè)Handler
private final mHandler = new Handler();
3、實(shí)現(xiàn)一個(gè)Runnable
/**
* 滾屏的線程
*/
private Runnable ScrollRunnable = new Runnable() {
@SuppressLint("NewApi")
@Override
public void run() {
// TODO Auto-generated method stub
int off = mLayout.getMeasuredHeight() - mScrollView.getHeight();// 判斷高度
if (off > 0) {
mScrollView.scrollBy(0, 50);
if (mScrollView.getScaleY() == off) {
Thread.currentThread().interrupt();
} else {
mHandler.postDelayed(this, 1000);
}
}
}
};
4、 開始滾動(dòng)
mHandler.post(ScrollRunnable);
5、 暫停滾動(dòng)
mHandler.removeCallbacks(ScrollRunnable);
6、ScrollView強(qiáng)制滑到底部
mScrollView.fullScroll(View.FOCUS_DOWN)