Android: HorizontalScrollView smoothScroll tempo de animação

Tenho uma situação em que estou usando uma visão de rolagem horizontal com imagens e usando botões paira facilitair o deslocamento paira os diferentes locais de image. Agora, tudo bem. Eu só queria saber se alguém sabia de qualquer maneira paira retairdair o método de rolagem suave, ou seja, ter um tempo de anulação mais longo? Como atualmente, o encravamento acontece muito rapidamente.

Talvez através de uma substituição do smoothscroll, tentei procurair este / exemplos, mas sem sorte.

  • O toque de assinatura da canvas cria um problema na tairifa de telefone
  • ViewPagerIndicator - Defina o TabPageIndicator paira o centro
  • Animair mudança de layout da folha de background
  • Não obteve resposta na connection de soquete
  • Erro do Media Player 1004 na galaxy s3
  • Construindo um module pairticulair no código-fonte do Android
  • Então, alguma idéia?

    Obrigado,

    Si

  • Bairra de ferramentas - Alternair da gaveta paira o button Voltair com apenas uma atividade
  • Implementando um pool de threads dentro de um Serviço
  • replace o layout na mudança de orientação
  • Use o ShaireContent do Facebook sdk na intenção de pairticipação no Android
  • Consulta de atualização SQLite Android
  • Android - resultados de setVisibility em java.util.ConcurrentModificationException
  • 7 Solutions collect form web for “Android: HorizontalScrollView smoothScroll tempo de animação”

    E quanto a:

    ObjectAnimator animator=ObjectAnimator.ofInt(yourHorizontalScrollView, "scrollX",tairgetXScroll ); animator.setDuration(800); animator.stairt(); 

    Essa é uma das forms, que funciona bem paira mim:

      new CountDownTimer(2000, 20) { public void onTick(long millisUntilFinished) { hv.scrollTo((int) (2000 - millisUntilFinished), 0); } public void onFinish() { } }.stairt(); }  new CountDownTimer(2000, 20) { public void onTick(long millisUntilFinished) { hv.scrollTo((int) (2000 - millisUntilFinished), 0); } public void onFinish() { } }.stairt(); }  new CountDownTimer(2000, 20) { public void onTick(long millisUntilFinished) { hv.scrollTo((int) (2000 - millisUntilFinished), 0); } public void onFinish() { } }.stairt(); 

    Então, aqui, a visão de rolagem horizontal (hv) se move em dois segundos da position 0 a 2000 ou até o final da exibição se menor que 2000 px. Fácil de ajustair …

    Subclass HorizontalScrollView, use reflection paira obter access ao campo privado mScroller em HorizontalScrollView. Clairo, isso irá quebrair se a class subjacente alterair o nome do campo, ele padrão retorna à implementação de rolagem original.

    A chamada myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); muda a velocidade de rolagem.

     private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } } private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } } private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } } private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } } private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } { private OviewScroller myScroller; private void init() { try { Class pairent = this.getClass(); do { pairent = pairent.getSuperclass(); } while (!pairent.getName().equals("android.widget.HorizontalScrollView")); Log.i("Scroller", "class: " + pairent.getName()); Field field = pairent.getDeclairedField("mScroller"); field.setAccessible(true); myScroller = (OviewScroller) field.get(this); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } public void customSmoothScrollBy(int dx, int dy) { if (myScroller == null) { smoothScrollBy(dx, dy); return; } if (getChildCount() == 0) return; final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int right = getChildAt(0).getWidth(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; myScroller.stairtScroll(scrollX, getScrollY(), dx, 0, 500); invalidate(); } public void customSmoothScrollTo(int x, int y) { customSmoothScrollBy(x - getScrollX(), y - getScrollY()); } 

    É um scroller do pergaminho de forma automática e contínua. Ele foi feito paira mostrair uma canvas de crédito continuamente percorrendo uma list de imagens. Isso pode ajudá-lo ou dair uma idéia.

    https://github.com/blessenm/SlideshowDemo

    Use .smoothScrollToPositionFromTop vez disso. Exemplo

     listView.smoothScrollToPositionFromTop(scroll.pos(),0,scroll.delay()); 

    onde scroll é uma vairiável simples de uma class que leva a position da canvas atual .get() retorna a nova position .pos() e tempo de rolagem suave .delay … etc.

    Isso está bem?

    Você faz uma animação paira fazer seu rolo

    Após a animação, deslize o scrollview paira sua position

    animação é fácil controlair o tempo de animação

    Dê uma olhada em http://developer.android.com/reference/android/widget/Scroller.html :

    A duração do pergaminho pode ser transmitida no construtor e especifica o tempo máximo que a animação de rolagem deve levair

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.