0
我想要做的是根据设备旋转了多少来在屏幕上移动一个对象。在活动中,OnSensorChanged在我创建的对象(其属性包括我想要移动的ImageView)上调用一个setPosition()方法。 SETPOSITION功能的方法是:用陀螺仪反馈在屏幕上翻译ImageView导致闪烁图像
void setPosition(float degree) { //degree = total number of degrees the device has rotated
float baseDegree = degree%360;
TranslateAnimation transAm;
if(baseDegree >= 0 && baseDegree < 90)
{
transAm = new TranslateAnimation(
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, this.y,
Animation.ABSOLUTE, (float)(maxY) - ((baseDegree*maxX)/360)); //maxX = screenWidth
transAm.setInterpolator(new LinearInterpolator());
transAm.setFillAfter(true);
//transAm.setFillEnabled(true); // I tried all of these solutions
//transAm.setDuration(1); // I found online, but none seemed
//transAm.setRepeatCount(1); // to work.
this.y = (float)(maxY) - ((baseDegree*maxY)/90);
this.image.startAnimation(transAm);
}
}
音符MAXX是屏幕宽度,MAXY是屏幕高度。
问题是图像似乎在应该出现的位置和应该出现的位置之间快速闪烁。我不知道如何让它留在一个地方,也不知道我是否可以很快地对图像上的太多动画进行调用,所以我也接受其他建议。
谢谢!