[英]android what should be pivot point to rotate image around its center of base
在標記重復或關閉之前,請仔細閱讀整個問題
我想圍繞其基點的中心點旋轉圖像(特別是箭頭圖像 )。
例如,在開始時,我的圖像將像9中的時鍾中的秒針。並且假設如果我將該圖像旋轉30度,它應該看起來像時鍾秒針10和120度時鍾秒針1。
所以我想圍繞它的基座中心(沿x軸)旋轉那個圖像。
那么如果我第一次編碼,我應該作為樞軸(X和Y)傳遞什么
imageView.setPivotX(1f);
imageView.setPivotY(1f);
imageView.setRotation(-30);
或第二個代碼
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
matrix.postRotate((float) 20, 0f, 0f);
imageView.setImageMatrix(matrix);
或第三代碼
Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_0_degree);
Matrix matrix = new Matrix();
matrix.postRotate(30);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 1, myImg.getWidth(), myImg.getHeight(), matrix, true);
imageView.setImageBitmap(rotated);
或第四個代碼
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
添加了一個圖像,以便更好地理解沿順時針方向旋轉90度。
我希望將來google會添加更多關於支點的文檔。
提前致謝。
第四個代碼^^幾乎是對的
你可以這樣做:
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, 30,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 1f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
mImageView.setAnimation(rotateAnim);
rotateAnim.start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.