如何在Android中翻转ImageView?

时间:2012-07-18 11:11:33

标签: android android-imageview

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

请帮帮我。

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

提前谢谢大家。

3 个答案:

答案 0 :(得分:7)

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

https://github.com/castorflex/FlipImageView

答案 1 :(得分:5)

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

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

查看this answer以了解要使用的确切代码。

答案 2 :(得分:4)

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

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

您必须将与imageview相关联的位图传递给翻转和翻转类型。例如,

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