java – 在Android上旋转图像而不缩小

我需要在我正在开发的应用程序上创建一个指南针.所以我试图创建一个名为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,bMap.getWidth(),bMap.getHeight(),xMatrix,true);
        setimageBitmap(bMapRotate);

任何帮助将不胜感激.谢谢

编辑:(解决方案)
我终于得到了工作,感谢接受的答案.这是我正在为任何想要知道如何工作的人使用的代码

RotateAnimation rAnimAntiClockwise = new RotateAnimation(
                    360 - mValue,360 - event.values[0],Animation.RELATIVE_TO_SELF,0.5f,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,0.5f);
        rAnimAntiClockwise.setFillAfter(true);
        rAnimAntiClockwise.setInterpolator(new LinearInterpolator());       
            bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.rotate);     
        rAnimAntiClockwise.setDuration(100);
        img_rotate.startAnimation(rAnimAntiClockwise);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...