私はスクロールビューを持っています。SmoothScrollBy()を使用してsmooth-scroll.を実行しました。すべて正常に動作しますが、smooth-scrollの期間を変更したいです。スムーズ スクロールが非常に速く発生し、ユーザーは何が起こったのか理解できません。スムーズ スクロールの速度を下げるのを手伝ってください。
51607 次
4 に答える
185
簡単な答えは交換するだけです
scrollView.smoothScrollTo(0, scrollTo);
と
ObjectAnimator.ofInt(scrollView, "scrollY", scrollTo).setDuration(duration).start();
whereduration
はミリ秒単位の時間です。
于 2015-10-08T10:55:42.383 に答える
14
次のコードを試してください。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
ValueAnimator realSmoothScrollAnimation =
ValueAnimator.ofInt(parentScrollView.getScrollY(), targetScrollY);
realSmoothScrollAnimation.setDuration(500);
realSmoothScrollAnimation.addUpdateListener(new AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
int scrollTo = (Integer) animation.getAnimatedValue();
parentScrollView.scrollTo(0, scrollTo);
}
});
realSmoothScrollAnimation.start();
}
else
{
parentScrollView.smoothScrollTo(0, targetScrollY);
}
于 2014-11-19T22:15:04.093 に答える
4
これが、スムーズな縦スクロール (映画のクレジットのような) を実現した方法です。これにより、ユーザーはスクロールを上下に動かしたり、離したときにスクロールを続けることもできます。私の XML では、"scrollView1" という名前の ScrollView 内に TextView をカプセル化しました。楽しみ!
final TextView tv=(TextView)findViewById(R.id.lyrics);
final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
Button start = (Button) findViewById(R.id.button_start);
Button stop = (Button) findViewById(R.id.button_stop);
final Handler timerHandler = new Handler();
final Runnable timerRunnable = new Runnable() {
@Override
public void run() {
scrollView.smoothScrollBy(0,5); // 5 is how many pixels you want it to scroll vertically by
timerHandler.postDelayed(this, 10); // 10 is how many milliseconds you want this thread to run
}
};
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timerHandler.postDelayed(timerRunnable, 0);
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timerHandler.removeCallbacks(timerRunnable);
}
});
于 2015-02-17T21:54:34.860 に答える
-2
whichScreen = Math.max(0, Math.min(whichScreen, getBase().getDocumentModel().getPageCount()-1));
mNextScreen = whichScreen;
final int newX = whichScreen * getWidth();
final int delta = newX - getScrollX();
//scroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);
scroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta));
invalidate();
于 2012-01-06T10:47:22.610 に答える