imageview旋轉的幾種方式


我整理了一下,大概有四種,親測成功三種。

第一種是最愚蠢的,不過看許多博客都使用這種方法,即旋轉bitmap:

Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.ic_launcher)).getBitmap();
Matrix matrix  = new Matrix();
matrix.setRotate(90);
Bitmap new = Bitmap.create(bitmap,0,bitmap.getWidth(),0,bitmap.getHeight(),matrix);
image.setBitmapResource(bitmap);

bitmap在不斷旋轉,又不回收內存,浪費大大噠,不推薦使用。

第二種,使用imageview自帶的旋轉方法

image.setPivotX(image.getWidth()/2);
image.setPivotY(image.getHeight()/2);//支點在圖片中心
image.setRotation(90);

第三種,使用旋轉動畫

                Animation rotateAnimation  = new RotateAnimation(lastAngle, progress, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1);
                rotateAnimation.setFillAfter(true);
                rotateAnimation.setDuration(50);
                rotateAnimation.setRepeatCount(0);
                rotateAnimation.setInterpolator(new LinearInterpolator());
                rotateImage.startAnimation(rotateAnimation);

第四種,其他博客看到的,親測不能實現,順便貼出來吧,看客哪個試出來了,請指導一下小弟!

Matrix matrix=new Matrix();
                rotateImage.setScaleType(ScaleType.MATRIX);   //required
                matrix.postRotate((float) progress, pivotX, pivotY);
                rotateImage.setImageMatrix(matrix);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM