How to flip ImageView in Android?

I am working on an application that I need to flip ImageView when touching and controlling the transfer to the second step.

Please help me.

I tried a lot, but I failed.

Thanks to everyone in advance.

+6
source share
3 answers

You can use Animation Apis, which are available for Android 3.0 and later.

If you need it before cellular, you can use the NineOldAndroids library.

Check this answer for exact code.

+5
source

Here is a good library for flipping images:

https://github.com/castorflex/FlipImageView

+7
source

You do not need to use any library, you can try a simple function to view the image in horizontal or vertical direction,

  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 need to transfer the bitmap associated with the reversal of the image so that it is flipped and flipped. For instance,

 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)); 
+4
source

Source: https://habr.com/ru/post/920790/


All Articles