Rotating an image around a specified point doesn't work! (Android)

后端 未结 2 686
攒了一身酷
攒了一身酷 2021-01-16 08:42

I\'m rotating an ImageView with postRotate(float degrees, float px, float py), setting px and py to a few differnt values including (0,0) and (imgView.getHeight(),imgView.ge

相关标签:
2条回答
  • 2021-01-16 09:22

    A slight "hack", you could probably adjust the image size using something like Paint.net or Gimp, depending on your OS. That would make the image appear to spin on another point. This solution would be pointless if you are planning on using a lot of images though. This is a spinning cube tutorial using opengl.

    0 讨论(0)
  • 2021-01-16 09:27

    I am using a custom ImageView where I set the angle rotation.

    public class CompassImage extends ImageView {
        private float angleRotation;
    
        public CompassImage(Context context) {
            super(context);
        }
    
        public CompassImage(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CompassImage(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public void setAngleRotation(float angleRotation) {
            this.angleRotation = angleRotation;
            invalidate();
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            Rect clipBounds = canvas.getClipBounds();
            canvas.save();
            canvas.rotate(angleRotation, clipBounds.exactCenterX(), clipBounds.exactCenterY());
            super.onDraw(canvas);
            canvas.restore();
        }
    }
    

    If you play around with clipBounds you may find that helpful.

    0 讨论(0)
提交回复
热议问题