简体   繁体   English

围绕另一个图像的中心旋转图像

[英]rotate image around a center of another image

I have rotated a dial around its center with the helop from the link below: 我在中心旋转了一个表盘,下面的链接是旋律:

http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/ http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/

Now I have an icon beside the dialer and I need to rotate it around the dialer, along with the dialer in a circular path. 现在我在拨号器旁边有一个图标,我需要围绕拨号器旋转它,以及拨号器在圆形路径中。

    private void rotateLogo(float degrees){
                 Matrix nMatrix = new Matrix();
                 Bitmap peopleOrg = BitmapFactory.decodeResource(getResources(), R.drawable.peoplelogo);
                 float translateX = dialerWidth / 2 - dialerWidth / 2;
                 float translateY = dialerHeight / 2 - dialerWidth / 2;
                 nMatrix.preTranslate(-turntable.getWidth()/2, -turntable.getHeight()/2);
                 nMatrix.postRotate(degrees, translateX, translateY);
                 nMatrix.postTranslate(turntable.getWidth()/2, turntable.getHeight()/2); 
                 Bitmap peopleScale = Bitmap.createBitmap(peopleOrg, 0, 0, peopleOrg.getWidth(), peopleOrg.getHeight(), nMatrix, true);
                 peopleLogo.setImageBitmap(peopleScale);        
                 peopleLogo.setImageMatrix(nMatrix);                  
    }

This just causes the image to rotate around its own center and not around the dialer's center point. 这只会使图像围绕其自身的中心旋转,而不是围绕拨号器的中心点旋转。 I cant find out where i am wrong :( 我不知道我错在哪里:(

Updates 更新

  1. I basically need the logo to move in a circular path and be a clickable view. 我基本上需要徽标在圆形路径中移动并且是可点击的视图。
  2. Tried using rotateAnim but the view doesnt animate and i have trouble getting the onclick event. 尝试使用rotateAnim但视图没有动画,我无法获得onclick事件。
  3. Would like any help that can rotate the same using matrices 想要任何可以使用矩阵旋转相同的帮助

Try only rotate with peopleOrg width and height. 尝试仅使用peopleOrg宽度和高度旋转。

nMatrix.postRotate(degrees, peopleOrg.getWidth()/2, peopleOrg.getHeight()/2);

Update : 更新:

Now that you let me know that your logo should be a clickable view, merging the logo image with your dialer is not applicable. 现在您告诉我您的徽标应该是可点击的视图,将徽标图像与拨号器合并不适用。 To rotate the logo view around the center of dialer you should be actually calculating the (top,left) point for your logo view and moving it around, than just rotating it. 要围绕拨号器中心旋转徽标视图,您应该实际计算徽标视图的(顶部,左侧)点并移动它,而不仅仅是旋转它。

Use sine and cosine functions to get the point on the circumference of an imaginary circle for drawing your logo view. 使用sinecosine函数获取假想圆周上的点以绘制徽标视图。

This post will help you with calculations : How do I calculate a point on a circle's circumference? 这篇文章将帮助您进行计算: 如何计算圆周长上的点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM