/ / Desplazar hacia arriba un ScrollView lentamente - android, scroll, scrollview

Desplazar hacia arriba un ScrollView lentamente - android, scroll, scrollview

La pregunta es "¿Cómo puedo desplazar hacia arriba un ScrollView hacia arriba de manera muy suave y lenta".

En mi caso especial, necesito desplazarme hacia arriba en aproximadamente 1-2 segundos. He intentado interpolar manualmente usando un controlador (llamando a scrollTo (0, y)) pero eso no funcionó en absoluto.

He visto este efecto en algunas aplicaciones de lectores de libros todavía, así que debe haber una forma, estoy seguro: D. (El texto se desplaza lentamente hacia arriba para seguir leyendo sin tocar la pantalla, haciendo entrada).

Respuestas

10 por respuesta № 1

En 2 segundos mueve la vista de desplazamiento a la posición de 2000.

new CountDownTimer(2000, 20) {

public void onTick(long millisUntilFinished) {
scrollView.scrollTo(0, (int) (2000 - millisUntilFinished)); // from zero to 2000
}

public void onFinish() {
}

}.start();

26 para la respuesta № 2

Lo hice usando el animador de objetos (disponible en API> = 3) y se ve muy bien:

Definir un ObjectAnimator: final ObjectAnimator animScrollToTop = ObjectAnimator.ofInt(this, "scrollY", 0);

(this se refiere a la clase que extiende Android "s ScrollView)

Puede establecer su duración como desee:

animScrollToTop.setDuration(2000); (2 segundos)

PD. No te olvides de comenzar la animación.


10 para la respuesta № 3

Prueba el siguiente código:

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

5 para la respuesta № 4

Has probado smoothScrollTo(int x, int y)? No puede configurar el parámetro de velocidad, pero tal vez esta función esté bien para usted


0 para la respuesta № 5

Podrías usar la clase Timer y TimerTask. Podrías hacer algo como

scrollTimer = new Timer();
scrollerSchedule = new TimerTask(){
@Override
public void run(){
runOnUiThread(SCROLL TO CODE GOES HERE);
}
};
scrollTimer.schedule(scrollerSchedule, 30, 30);