对象动画仅在中间起作用,而不在滚动到底部时起作用。

huangapple go评论73阅读模式
英文:

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());

huangapple
  • 本文由 发表于 2020年9月6日 14:56:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63761535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定