Preethi
Preethi

Reputation: 154

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/

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.
  3. Would like any help that can rotate the same using matrices

Upvotes: 3

Views: 2308

Answers (1)

Ron
Ron

Reputation: 24233

Try only rotate with peopleOrg width and height.

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.

This post will help you with calculations : How do I calculate a point on a circle’s circumference?

Upvotes: 2

Related Questions