我有HorizontalScrollView和6个ImageViews。我从Parse.com获取图像。我希望HorizontalScrollView在活动开始时缓慢滚动。我已经阅读了参考文献,但无法解决它。我试过这个方法:
new Handler().postDelayed(new Runnable() {
public void run() {
horizontalScrollView1.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
//horizontalScrollView1.smoothScrollBy(500, 0);
}
}, 4000L);
但是有了这个,它的滚动速度太快了。也许我可以在循环中处理HorizontalScrollView,这样每个ImageView都会无限地重复自己。有没有办法做到这一点。感谢
答案 0 :(得分:4)
检查一下..
android.widget.HorizontalScrollView horScrlView;
Handler mHandler = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
horScrlView.smoothScrollBy(5, 0);
mHandler.sendMessageDelayed(new Message(), 1000);
return false;
}
});
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
* @author Hardik Shah
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.horizontal_scroll_view);
horScrlView = (android.widget.HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
mHandler.sendMessageDelayed(new Message(), 1000);
}
答案 1 :(得分:0)
我没有尝试过,但应该可以工作:
horizontalScrollView1.animate().setDuration(2000).withEndAction(new Runnable() {
@Override
public void run() {
horizontalScrollView1.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
});