Estoy usando GestureDetector en ViewFlipper para implementar showPrevious y showNext. Todo está bien. Sin embargo, quiero tener el efecto de que la animación de ViewFlipper sigue el gesto con el dedo de inmediato, en lugar de hacer un gesto. ¿Algún consejo?Android ViewFlipper que sigue gestos inmediatamente
7
A
Respuesta
5
Por lo que sé, tienes que hacerlo manualmente. El siguiente código debe indicarle la dirección correcta. Tienes que agregar animaciones dinámicas para que la vista no parpadee durante la flipp. Hay más cosas que debe hacer, dependiendo del contenido del viewflipper, pero debe comenzar.
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
//Gets the startpoint for you finger
pressDownPoint = event.getX();
//Gets how many view there is in the viewflipper
flipperViewCount = flipper.getChildCount();
//Checks if there is a view to the left of the current view
//if there is, it positions it to the left of the current view
if (flipper.getDisplayedChild() > 0)
{
View leftChild = flipper.getChildAt(flipper.getDisplayedChild() - 1);
//You must set the left view to invisible or visible
//or it will not move to the position you tell it
leftChild.setVisibility(View.INVISIBLE);
leftChild.layout(-screenWidth,
leftChild.getTop(), 0,
leftChild.getBottom());
}
//Same as above but for the view to the right
if (flipper.getDisplayedChild() < flipperViewCount - 1)
{
View rightChild = flipper.getChildAt(flipper.getDisplayedChild() + 1);
rightChild.setVisibility(View.INVISIBLE);
rightChild.layout(screenWidth,
rightChild.getTop(), screenWidth * 2,
rightChild.getBottom());
}
break;
}
case MotionEvent.ACTION_UP:
{
//Gets the absolute position on the screen
float releasePoint = event.getRawX();
//Calculates if the fling is to the right or left
//The screenDensity variable is simply the density of the device
//Have in mind that this will not flipp the viewflipper if you drag
//your finger less than about 0.5cm (depeding on the device)
//In that case you need to make an animation that takes the view back
//to its original position. Else it will just get stuck where you
//let go with your finger.
if (Math.abs(pressDownPoint - releasePoint)/screenDensity > 30)
{
if (pressDownPoint > releasePoint)
{
myAnimLeft(); //Method with your animation
flipper.showNext();
}
else
{
myAnimRight();
flipper.showPrevious();
}
}
break;
}
case MotionEvent.ACTION_MOVE:
{
View currentView = flipper.getCurrentView();
//Moves the current view
//screenWidth is based on the current devices screen width
currentView.layout((int)(event.getRawX() - pressDownPoint),
currentView.getTop(), (int)(event.getRawX() - pressDownPoint) + screenWidth,
currentView.getBottom());
//Moves the view to the left if there is one
if (flipper.getDisplayedChild() > 0)
{
View leftChild = flipper.getChildAt(flipper.getDisplayedChild() - 1);
leftChild.layout((int)(event.getRawX() - pressDownPoint - screenWidth),
leftChild.getTop(), (int)(event.getRawX() - pressDownPoint),
leftChild.getBottom());
//Sets the left view to visible so it shows
if (leftChild.getVisibility() == View.INVISIBLE)
{
leftChild.setVisibility(View.VISIBLE);
}
}
//Same as above but for the view to the right
if (flipper.getDisplayedChild() < flipperViewCount - 1)
{
View rightChild = flipper.getChildAt(flipper.getDisplayedChild() + 1);
rightChild.layout((int)(event.getRawX() - pressDownPoint + screenWidth),
rightChild.getTop(), (int)(event.getRawX() - pressDownPoint + (screenWidth * 2)),
rightChild.getBottom());
if (rightChild.getVisibility() == View.INVISIBLE)
{
rightChild.setVisibility(View.VISIBLE);
}
}
}
}
return true;
}
Cuestiones relacionadas
- 1. Android ViewFlipper Animation
- 2. Android ViewFlipper no voltear
- 3. Android: ViewFlipper animación
- 4. Android, gestos sobre widgets clicables
- 5. Cómo detener Android ViewFlipper para que no se repita?
- 6. Gestos verticales y horizontales en Android
- 7. Reconocimiento de gestos en Android
- 8. Android: detección de gestos arrojadizos
- 9. Buscando Android ViewFlipper Ejemplo con múltiples WebViews
- 10. Mejor implementación de Rotate3dAnimation en Android ViewFlipper
- 11. Detección de gestos y problema ScrollView
- 12. Inmediatamente mostrar autocompletar en Android
- 13. pthread_cond_timedwait que vuelve inmediatamente
- 14. Android Score de predicción de gestos Rango
- 15. Fragmento de Android onCreateView con gestos
- 16. Sin animación con ViewFlipper?
- 17. Problemas para detectar gestos en ListView
- 18. cómo verificar el valor anterior en android of viewflipper
- 19. ¿Cómo maneja Viewflipper el botón Atrás en Android?
- 20. ViewFlipper vs Fragments
- 21. ViewFlipper tiene retraso "enorme"
- 22. Actualizar altura con ViewFlipper
- 23. Cómo configurar imágenes dinámicas en ViewFlipper en android?
- 24. ViewFlipper en widgets de aplicación
- 25. __bases__ no funciona! ¿Que sigue?
- 26. SVG está muriendo? ¿Que sigue?
- 27. acelerómetro Smartphone gestos algoritmos
- 28. Cómo agregar mediante programación vista en ViewFlipper
- 29. ¿La mejor práctica para viewflipper que contiene 10 linearlayouts?
- 30. Gestos y cadena de respuesta