安卓旋转动画
发布时间: 2024-07-19 02:47:40
㈠ 安卓开发 指南针图片旋转
添加图片的旋转动画就可以了,以图片中心为轴根据旋转的角度做旋转动画
既然知道做指南针就应该知道传感器吧,下面是做旋转监听的主要代码:
@Override
public void onSensorChanged(SensorEvent event) {
int sensorType = event.sensor.getType();
switch (sensorType) {
case Sensor.TYPE_ORIENTATION:
//获取绕Z轴转过的角度
float degree = event.values[0];
//创建旋转动画(反向转过的角度)
RotateAnimation ra = new RotateAnimation(currentDegree,
-degree, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
//设置动画的持续时间
ra.setDuration(200);
//运行动画
mImageView.startAnimation(ra);
currentDegree = -degree;
break;
default:
break;
}
}