8

I am working on an application I need to flip ImageView on touch and transfer control to the second activity.

Please help me.

I tried a lot but I haven't succeed.

Thank you all in advance.

transilvlad
  • 13,974
  • 13
  • 45
  • 80
Maulik.J
  • 636
  • 1
  • 6
  • 14

3 Answers3

7

Here is a nice library to flip images:

https://github.com/castorflex/FlipImageView

Bakyt
  • 1,268
  • 11
  • 10
7

You dont need to use any library, you can try following simple function to flip imageview either horizontally or vertically,

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

You will have to pass bitmap associated with imageview to be flipped and flipping type. For example,

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));
akshay7692
  • 601
  • 1
  • 8
  • 19
5

You can use the Animation Apis which are available for Android 3.0 and above.

If you need it pre-honeycomb, you can use a library called NineOldAndroids.

Check out this answer for the exact code to use.

Community
  • 1
  • 1
Benito Bertoli
  • 25,285
  • 12
  • 54
  • 61