[英]Rotate an imageView without changing its size Android
我想在RelativeLayout內分配ImageView多次。 為此,我使用:
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的大小。 我不知道如何不改變尺寸。
有什么幫助嗎? 非常感謝你。
您不能簡單地使用xml文件來創建旋轉動畫嗎? http://developer.android.com/guide/topics/resources/animation-resource.html
這是我在一個應用程序中使用的代碼,用於基於位圖旋轉圖像。
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);
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.