2012-09-18 122 views
-1

我想在方向上旋轉ImageButtons depand。但沒有重新開始活動。該圖像應該旋轉,但視圖不應該。 [例如:默認的相機應用]任何想法?我認爲我應該修復方向(android:screenOrientation =「portrait」)。Android旋轉圖像

如果您旋轉手機,該活動將無法重建。但底部(或側面)的圖標會旋轉。我怎樣才能做到這一點?

例如http://www.youtube.com/watch?v=hT3stvtv_1c在00:40 - 只有圖標旋轉,而不是孔觀點

+0

你的問題很混亂。請提供一些額外的說明或包含您當前的一些代碼。 –

+0

添加了一個視頻,我希望你能看到我的意思 – nikmaster

回答

5
Matrix matrix = new Matrix(); 
Bitmap b; 
//... 
imageView.setImageBitmap(b); 
//... 
// screen rotation 
matrix.postRotate(90); 
b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); 
imageView.setImageBitmap(b); 
4

可以使用ExifInterface

Matrix matrix = new Matrix(); 
    int orientation = 1; 
    try { 
     ExifInterface exif = new ExifInterface(filePath); 
     orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    matrix.setRotate(0); 
    switch (orientation) { 
    case ExifInterface.ORIENTATION_ROTATE_90: 
     matrix.setRotate(ROTATION_DEGREE); 
     break; 
    case ExifInterface.ORIENTATION_ROTATE_180: 

     matrix.setRotate(ROTATION_DEGREE * 2); 
     break; 
    case ExifInterface.ORIENTATION_ROTATE_270: 
     matrix.setRotate(-ROTATION_DEGREE); 
     break; 
    default: 
     break; 
    } 
1

如果妳從文件中獲取轉動信息想要點擊按鈕動態旋轉圖像全局定義

 int angle; int valueangle = 0; 

和使用的onclick按鈕 mrotate.setOnClickListener(新OnClickListener(){

 @Override 
     public void onClick(View v) { 

      // TODO Auto-generated method stub 
    ImageView mainimage22 = (ImageView) findViewById(R.id.mainimage22); 
    Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.image); 

      angle = valueangle + 90; 
      valueangle = angle; 
      System.out.println("valueangle"+valueangle); 
      if(valueangle == 360){ 
       valueangle=0; 
       System.out.println("00"+valueangle); 
      } 
      System.out.println("angle"+angle); 

      main_img.setVisibility(View.INVISIBLE); 

      Matrix matrix = new Matrix(); 
      matrix.postRotate(angle); 

      Bitmap rotated = Bitmap.createBitmap(myImg , 0, 0, 
        myImg .getWidth(), myImg .getHeight(), matrix, true); 


      mainimage22.setImageBitmap(rotated); 

     } 
    }); 
0

我用OrientationEventListener的並實施了方法onOrientationChanged(int orientation)。在我的MainActivity中。這是力變爲縱向我創建調用的實例,並開始跟蹤旋轉:

公共類RotationDetector擴展OrientationEventListener

在我的MainActivity

mOrientationListener =新RotationDetector (這個); mOrientationListener.enable();

不要忘了disable()它,當你不使用它了。並注意MaliEGL錯誤。