KSu*_*edi 10 java android image rotation
我需要在我正在处理的应用程序上创建指南针.所以我试图创建一个名为CompassView的新视图,它基本上扩展了imageview,显示了一个东西南北指向的位图,使用传感器查找手机指向的度数,并相应地旋转图像以便创建它一个真正的罗盘.但问题是,如果我尝试将图像旋转到某些角度(如45度),它会缩小.这里有一些图片可以更好地解释它.


正如你所看到的,当我试图在45左右旋转时,第二个图像会缩小.我想要它做的是:

这是我目前使用的代码:
        Bitmap bMap = BitmapFactory.decodeResource(getResources(),
                R.drawable.compass);
        Matrix xMatrix = new Matrix();
        xMatrix.reset();
        xMatrix.postRotate(360-mValue, 75, 75); //This is 75 because 150 is the image width
        Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
                bMap.getWidth(), bMap.getHeight(), xMatrix, true);
        setImageBitmap(bMapRotate);
任何帮助,将不胜感激.谢谢
编辑:(解决方案) 由于接受的答案我终于得到了它.以下是我想要知道它是如何工作的人使用的代码:
RotateAnimation rAnimAntiClockWise = new RotateAnimation(
                    360 - mValue, 360 - event.values[0],
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
//mValue is the angle in degrees and i subtracted it from 360 to make it anticlockwise, and event.values[0] is the same thing as mValue
rAnimAntiClockWise.setFillAfter(true);
rAnimAntiClockWise.setInterpolator(new LinearInterpolator());
rAnimAntiClockWise.setDuration(0);
startAnimation(rAnimAntiClockWise);
您可以使用另一种技巧,其工作方式与旋转相同,并且不会调整图像大小。实际上,我将图像旋转 45 度角,并在动画后保持变化。
rAnimAntiClockWise = new RotateAnimation(0.0f, 45.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        rAnimAntiClockWise.setFillAfter(true);
        rAnimAntiClockWise.setInterpolator(new LinearInterpolator());       
            bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.rotate);     
        rAnimAntiClockWise.setDuration(100);
        img_rotate.startAnimation(rAnimAntiClockWise);