2012-07-18 35 views
6

Estoy trabajando en una aplicación que necesito para voltear ImageView en contacto y transferir el control a la segunda actividad.Cómo voltear ImageView en Android?

Por favor, ayúdame.

Lo intenté mucho, pero no he tenido éxito.

Gracias a todos de antemano.

+2

Probé mucho, ¿Qué has intentado? Publica aquí. –

Respuesta

5

Puede utilizar los Apis de animación que están disponibles para Android 3.0 y superior.

Si lo necesita pre-nido de abeja, puede utilizar una biblioteca llamada NineOldAndroids.

Consulte this answer para obtener el código exacto para usar.

4

Usted no necesita utilizar cualquier biblioteca, puede intentar siguiente función para voltear imageview ya sea horizontal o verticalmente,

final static int FLIP_VERTICAL = 1; 
    final static int FLIP_HORIZONTAL = 2; 
    public static Bitmap flip(Bitmap src, int type) { 
      // create new matrix for transformation 
      Matrix matrix = new Matrix(); 
      // if vertical 
      if(type == FLIP_VERTICAL) { 
       matrix.preScale(1.0f, -1.0f); 
      } 
      // if horizonal 
      else if(type == FLIP_HORIZONTAL) { 
       matrix.preScale(-1.0f, 1.0f); 
      // unknown type 
      } else { 
       return null; 
      } 

      // return transformed image 
      return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); 
     } 

Deberá pasar el mapa de bits asociado con la vista de la imagen para que se invierta y se voltee el tipo. Por ejemplo,

ImageView myImageView = (ImageView) findViewById(R.id.myImageView); 
Bitmap bitmap = ((BitmapDrawable)myImageView.getDrawable()).getBitmap(); // get bitmap associated with your imageview 
myImageView .setImageBitmap(flip(bitmap ,FLIP_HORIZONTAL));