2013-02-08 2 views
0
public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     //accel 
     sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 
     sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); 



     setContentView(R.layout.sample); 
    } 

    ///////////////// Basics 
    /** 
    * Called when the application is in the background 
    */ 
    public void onPause() 
    { 
     super.onPause(); 
     sensorManager.unregisterListener(this); 

     //this is important because Android applications 
     //do not close, they are in the background 
     //so resources would be hogged otherwise 
    } 

    /** 
    * Called when the application is started 
    * or in the foreground again 
    */ 
    public void onResume() 
    { 
     super.onResume(); 
     sensorManager.registerListener(this, sensor, rate); 

    } 

    //==================Accel===================== 
    /** 
    * Called when the values of the acceleration sensor changes 
    * 
    * @param e Details about the change 
    */ 
     public void onSensorChanged(SensorEvent e) 
     { 
      float azimuth=e.values[0]; 

        Log.i("azimuth",String.valueOf(azimuth)); 


     } 

     /** 
     * Called when accuracy of the sensor is changed 
     * 
     * @param sen Which sensor's accuracy changed 
     * @param acc The new accuracy degree 
     */ 
     public void onAccuracyChanged(Sensor sen, int acc) 
     { 
     } 

여기 센서 매니저를 사용하여 방위각 값을 얻고 있습니다 .i 방위각 값을 사용하여 나침반처럼 imageview를 회전하는 방법을 알고 싶습니다. 누구나 아이디어를 줄 수 있습니까? OnDraw 함수를 사용하는 방법은 무엇입니까? OnDraw 메서드 안에 원이나 선을 그리지 않고? 여기android의 센서 관리자 방위각 값을 사용하여 이미지를 회전하는 방법은 무엇입니까?

답변

0

는 이미지 뷰를 회전하는 방법은 다음과 같습니다 API 11 + 들어

Matrix matrix=new Matrix(); 
imageview.setScaleType(ScaleType.MATRIX); //required 
matrix.postRotate((float) -azimuth, imageview.getDrawable().getBounds().width()/2, 
imageview.getDrawable().getBounds().height()/2);    

imageview.setImageMatrix(matrix); 

는 쉬운 방법이 있습니다 :

arrow.setRotation((float) -azimuth); 

당신은 원과 라인 나침반이 blog을 확인할 수 있습니다.

희망이 도움이됩니다.

관련 문제