如何在Android中翻转ImageView?

Mau*_*k.J 7 android android-imageview

我正在开发一个应用程序,我需要ImageView触摸触摸并将控制转移到第二个活动.

请帮我.

我尝试了很多,但我没有成功.

谢谢大家.

Bak*_*kyt 7

这是一个翻转图像的好库:

https://github.com/castorflex/FlipImageView


aks*_*692 6

您不需要使用任何库,您可以尝试以下简单的功能来水平或垂直翻转图像视图,

    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);
        }
Run Code Online (Sandbox Code Playgroud)

您必须传递与要翻转的图像视图相关联的位图和翻转类型。例如,

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));
Run Code Online (Sandbox Code Playgroud)


Ben*_*oli 5

您可以使用适用于Android 3.0及更高版本的动画Apis.

如果您需要预蜂窝,可以使用名为NineOldAndroids的库.

查看此答案以获取要使用的确切代码.