您的位置:首页 > 其它

利用ScrollView实现布局自动滚动

2014-02-12 17:32 375 查看
转自:http://www.getcn.net/index.php?mod=skill&action=detail&id=44042

首先1,

获得ScrollView sc = (ScrollView) findViewById(R.id.scroll);//scroll对象

LinearLayout mlayout = (LinearLayout) findViewById(R.id.mlayout);//scrollView中包含的布局对象

2,定义一个Handler

private final Handler mHandler = new Handler();

3,实现一个线程

Copy to clipboard

private Runnable ScrollRunnable= new Runnable() {

@Override

public void run() {

int off = mlayout.getMeasuredHeight() - sc.getHeight();//判断高度 if (off > 0) {

sc.scrollBy(0, 30);

if (sc.getScrollY() == off) {

Thread.currentThread().interrupt();

} else {

mHandler.postDelayed(this, 1000);

}

}

}

};

4,开始滚动

mHandler.post(ScrollRunnable);

5,暂停滚动

mHandler.removeCallbacks(ScrollRunnable);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: