2012-07-18 76 views
6

我正在处理一个应用程序,我需要将触摸屏上的ImageView翻转到第二个活动。如何在Android中翻转ImageView?

请帮帮我。

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

谢谢大家提前。

+2

试了很多,你试过了什么?张贴在这里。 – 2012-07-18 11:19:34

回答

5

您可以使用适用于Android 3.0及以上版本的Animation Apis。

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

检查出this answer准确的代码使用。

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