Android 如何根据相机旋转来旋转ImageButton?
我正在做一个自定义的相机布局。它有一个framelayout和imagebutton。我想根据相机的旋转来旋转这个按钮。所以每当我在图像中旋转相机时,按钮应该朝向正确的方向。 但我不知道怎么做。这是我的密码Android 如何根据相机旋转来旋转ImageButton?,android,layout,camera,Android,Layout,Camera,我正在做一个自定义的相机布局。它有一个framelayout和imagebutton。我想根据相机的旋转来旋转这个按钮。所以每当我在图像中旋转相机时,按钮应该朝向正确的方向。 但我不知道怎么做。这是我的密码 public class CameraActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)
public class CameraActivity extends Activity
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.camera_layout);
btnCapture = (ImageButton)findViewById(R.id.btn_capture);
mCamera = getCameraInstance();
mPreview = new CameraPreview(this, mCamera);
FrameLayout camPreview = (FrameLayout)findViewById(R.id.camera_preview);
camPreview.addView(mPreview);
}
}
我确实不太明白这个问题。当用户旋转设备(相机)时,您的活动将被破坏,并使用新的屏幕布局创建一个新实例。您的按钮应该按预期向上。@jboi否,我的布局是固定的。但我要找的是,当我把相机旋转90*/180*/270*时,我的拍摄按钮也应该是旋转的。。