我需要使用360度全景图,但没有图库。我想我可以使用加速度计来完成这项任务。但是我不知道如何实现它。 也许有另一种方法?还是加速度计是最好的方法?
(它必须看起来像是带有imageview的片段,带有360张照片,如果旋转手机,照片也会旋转)
对不起,英语。谢谢
private SensorManager sensorManager;
private Sensor accelerometer;
private static int x = 0;
private static int y = 0;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getContext() != null)
sensorManager = (SensorManager) getContext().getSystemService(SENSOR_SERVICE);
if (sensorManager != null)
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
return root;
}
@Override
public void onResume() {
super.onResume();
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
}
@Override
public void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
x -= (int) sensorEvent.values[0];
y += (int) sensorEvent.values[1];
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}