英文:
Object animator works only till the middle, not the bottom of scroll
问题
动画启动,但仅进行到滚动中间的特定位置。是什么原因导致了这种奇怪的行为?请给予一些建议!
public void scrollAnimation() {
// 滚动的操作!
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();
}
});
}
英文:
Animation launches, but goes only till the particular spot somewhere in the middle of the scroll. What could cause such strange behavior? Please, help with some advice!
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();
}
});
}
答案1
得分: 0
AnimatorSet animators = new AnimatorSet();
int y = 8000; // 滚动距离(以像素为单位)
final ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollViewID);
final ObjectAnimator yTranslate = ObjectAnimator.ofInt(mScrollView, "scrollY", y);
animators.setDuration(100000L); // 滚动速度(值越大,速度越快)
animators.play(yTranslate);
animators.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();
答案2
得分: 0
你需要2个值,我认为是这样的:
ObjectAnimator.ofInt(v, "scrollY",
v.getChildAt(0).getHeight()
- v.getHeight());
英文:
You need 2 values i think. Like this
ObjectAnimator.ofInt(v, "scrollY",
v.getChildAt(0).getHeight()
- v.getHeight());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论