2014-08-31 109 views
0

我想在RelativeLayout中多次渲染ImageView。 要做到这一点,我使用:在不改变大小的情况下旋转imageView Android

angleRotation = angleRotation + (float)90; 

     Rect bounds = imgToRotate.getDrawable().getBounds(); 

     Matrix matrix=new Matrix(); 
     imgToRotate.setScaleType(ScaleType.MATRIX); //required 
     matrix.postRotate((float) angleRotation, bounds.width()/2 , bounds.height()/2); 
     imgToRotate.setImageMatrix(matrix); 

的问题是,我使用矩阵改变我的ImageView的大小。我不知道如何不改变大小。

任何帮助?非常感谢你。

+0

你的意思是图像改变了尺寸以便缩小/缩小?或者图像不是方形的,你的意思是newWidth = oldHeight && newHeight = oldWidth? – 2014-08-31 16:47:46

+0

我的意思是图像保持比例,但它被缩小。 – user2335528 2014-08-31 16:50:27

回答

0

难道你不能简单地使用一个XML文件来创建一个旋转动画? http://developer.android.com/guide/topics/resources/animation-resource.html

+0

我需要将此图像写入文件您认为如果我使用旋转图像将在写入后旋转? – user2335528 2014-08-31 16:43:40

+0

我真的不确定要真正理解这个问题。 – soueuls 2014-08-31 16:44:54

+0

我想写我的形象缓存,我不知道是否应用旋转动画,如果图像将有旋转应用一旦我写它缓存。 – user2335528 2014-08-31 16:46:33

0

这是我在我的一个应用程序中使用的代码来旋转基于位图的图像。

Matrix mtx = new Matrix(); 
mtx.preRotate(90); 
Bitmap rotatedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, w, h, mtx, true); 

之后,您可以将图像位图设置为imageView。 我假设你可以保留(或得到)你的原始位图的引用。

编辑: 如果你的目标API 11和最多可以使用方法:

View.setRotation(float angle); 

希望它能帮助。

+0

是的,我已经试过这种方式,问题是我每次创建一个新的位图时,增长堆。 – user2335528 2014-08-31 17:30:46

+0

你想要什么API? – 2014-08-31 18:03:10

+0

Api最小值为10 – user2335528 2014-08-31 18:09:13