1、 獲得ScrollView對象和ScrollView中包含的布局對象
mScrollView = (ScrollView) findViewById(R.id.l_rp_ques_main_scrollview);
mLayout = (LinearLayout) findViewById(R.id.l_rp_ques_main_scrolllayout);
2座菠、在主線程定義一個Handler
private final mHandler = new Handler();
3、實現一個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膀斋、 開始滾動
mHandler.post(ScrollRunnable);
5、 暫停滾動
mHandler.removeCallbacks(ScrollRunnable);
6识藤、ScrollView強制滑到底部
mScrollView.fullScroll(View.FOCUS_DOWN)