首先
private Runnable runnable = new Runnable() {
@Override
public void run() {
scrollToPosition(0,600);
}
};
其次
handler.post(runnable);
最后
public void scrollToPosition(int x,int y) {
ObjectAnimator xTranslate = ObjectAnimator.ofInt(ScrollContainer, "scrollX", x);
ObjectAnimator yTranslate = ObjectAnimator.ofInt(ScrollContainer, "scrollY", y);
AnimatorSet animators = new AnimatorSet();
animators.setDuration(1000L);
animators.playTogether(xTranslate, yTranslate);
animators.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
}
});
animators.start();
}
即可