我需要在我正在处理的应用程序上创建指南针.所以我试图创建一个名为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);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢
编辑:(解决方案) 由于接受的答案我终于得到了它.以下是我想要知道它是如何工作的人使用的代码:
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); …Run Code Online (Sandbox Code Playgroud) 我一直试图在一行中的两个字符串之间得到一个字符串.我发现了许多使用正则表达式的教程,但由于我对正则表达式不太好,我无法弄清楚如何做到这一点.任何帮助将不胜感激.
var fullUrl = "http://something.com/File/?URL=http://www.wireshock.com/&IP=0.0.0.0&CAT=BLOG&USER=MAND\\DEFAULT\\market4080";
Run Code Online (Sandbox Code Playgroud)
我需要找到一种方法来获取http://something.com/File/?URL=和&IP =之间的字符串,然后返回http://www.wireshock.com.我不想将字符串从"&"拆分并获取中间字符串,因为它会破坏一些带有&字符的URL.任何帮助,将不胜感激.谢谢 :)
我正在尝试制作一个小程序,将鼠标从当前位置移动到给定位置.这是一个我可以使用的方法,它将鼠标从一个点移动到另一个点,但没有动画:
moveMouse(int x, int y);
Run Code Online (Sandbox Code Playgroud)
这会将鼠标从当前坐标移动到屏幕上的x,y而不动画.现在我的工作是将鼠标移动到该坐标,但它也应该显示鼠标一次移动一个像素.我需要创建一个循环,一次将鼠标光标移动几个像素x和y,这样我就是这样想的:
public void moveMouseAnimation(x,y){
//Integers x2 and y2 will be the current position of the mouse cursor
boolean isRunning = true;
while(isRunning){
delay(10); // <- 10 Milliseconds pause so that people can see the animation
x2 -= 1;
y2 -= 1;
moveMouse(x2,y2);
if(x2 == x && y2 == y) isRunning = false; //Ends loop
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要找到正确的x2和y2值,以便鼠标沿直线移动并最终到达x和y.有人能帮助我吗