展会信息港展会大全

利用ScrollView实现布局自动滚动 android开发学习
来源:互联网   发布日期:2015-10-03 10:51:39   浏览:3006次  

导读:首先1,获得ScrollViewsc = (ScrollView) findViewById(R.id.scroll);//scroll对象LinearLayout mlayout = (LinearLayout) findViewById(R.id.mlayout);//scrollView中包含的布局对象2,定义一个Handlerp......

首先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,实现一个线程

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 自动滚动

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港