利用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);
首先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);
相关文章推荐
- 利用ScrollView实现布局自动滚动
- 利用ScrollView实现布局自动滚动
- 利用ScrollView实现布局自动滚动
- 利用ScrollView实现布局自动滚动
- Android 利用ScrollView实现布局自动滚动
- 禁止ScrollView在子控件的布局改变时自动滚动的的方法
- iOS】利用PureLayout实现:比例自动布局(AutoLayout)
- iOS-利用UIScrollView实现展示图片的无限滚动及自动滚动
- iOS中scrollview自动滚动的实现
- IOS8下利用自动布局实现键盘的弹出效果
- Android学习笔记__实现布局自动滚动
- android 实现ScrollView自动滚动
- 禁止ScrollView在子控件的布局改变时自动滚动
- iOS中scrollview自动滚动的实现
- iOS-利用UIScrollView实现展示图片的无限滚动及自动滚动
- 禁止ScrollView在子控件的布局改变时自动滚动的的方法
- 禁止ScrollView在子控件的布局改变时自动滚动的的方法
- 利用html中的div标签实现网页中某一块区域的自动滚动
- 手动控制ScrollView滚动,ScrollView添加子布局,自动向上滚动
- iOS-利用UIScrollView实现展示图片的无限滚动及自动滚动