问题描述
动画将启动,但仅持续到滚动中间的某个特定位置。什么会导致这种奇怪的行为?请帮忙一些建议!
public void scrollAnimation() {
// Scroll activity!
final ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollViewID);
mScrollView.post(new Runnable() {
public void run()
{
ObjectAnimator anim = ObjectAnimator.ofInt(mScrollView,"scrollY",mScrollView.getBottom());
anim.setDuration(3000);
anim.start();
}
});
}
解决方法
AnimatorSet animators = new AnimatorSet();
int y = 8000; // pixels how far will go the scroll
final ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollViewID);
final ObjectAnimator yTranslate = ObjectAnimator.ofInt(mScrollView,"scrollY",y);
animators.setDuration(100000L); // speed of scroll (greater the value -- greater the speed)
animators.play(yTranslate);
animators.start();