0

I want to rotate a specific image on an acitivity. I found everything where we set the contentview to an image, or drawing something, but again full screen.

sensorChanged method:

float[] mGravity2;
  float[] mGeomagnetic2;

  public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
      mGravity2 = event.values;
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
      mGeomagnetic2 = event.values;
    if (mGravity2 != null && mGeomagnetic2 != null) {
      float R[] = new float[9];
      float I[] = new float[9];
      boolean success = SensorManager.getRotationMatrix(R, I, mGravity2, mGeomagnetic2);
      if (success) {
        float orientation[] = new float[3];
        SensorManager.getOrientation(R, orientation);
        azimut = orientation[0]; 
      }
    }
    adjustArrow(azimut);
  }

adjustArrow method:

private void adjustArrow(float azz) {
    // TODO Auto-generated method stub
    ImageView myIB = (ImageView) findViewById(R.id.imageView1);
    Matrix matrix=new Matrix();
    myIB.setScaleType(ScaleType.MATRIX); 
    matrix.postRotate((float) azz, 200,200);
    myIB.setImageMatrix(matrix);
}

and in onCreate method i put the initial picture, with any beering or with 0 degrees set:

ImageView myIB = (ImageView) findViewById(R.id.imageView1);

    Matrix matrix=new Matrix();
    myIB.setScaleType(ScaleType.MATRIX); 
    matrix.postRotate((float) degree(), 200,200);
    myIB.setImageMatrix(matrix);

but it is not working, and i don't know why. As from the sensorChanged method it have to take azimut and in "adjustArrow" method it have to rotate the picture. Thanks in advance

4

0 回答 0