0
我尝试使用搜索,但没有找到解决此问题的方法。 我有一个固定横向的摄像头应用程序。 orientationEventListener正确旋转我的所有按钮。但是,有些按钮应显示对话框或警告对话框,并且这些对话框不会旋转。以下是在MainActivity旋转对话框和AlertDialog以外的固定设备方向
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(CameraActivity.this);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setContentView(R.layout.layout_dialog_mode);
// set up texts in layout_dialog_mode
和
private void createMenu() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final String[] modeS = {getString(R.string.mode_1), getString(R.string.mode_2), getString(R.string.mode_3), getString(R.string.mode_4), getString(R.string.mode_5)};
builder.setTitle(getString(R.string.mode_title));
builder.setSingleChoiceItems(modeS, mode, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
// set things as chosen by user
}
dialog.dismiss(); /* close menu after selection */
}
});
builder.show();
}
layout_dialog_mode相关缩短代码被包含TextViews和ImageViews一个的LinearLayout。
按钮的旋转是这样工作的:
private void initialiseOEListener() {
oEListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
try {
if (orientation == ORIENTATION_UNKNOWN) return;
orientation = (orientation + 45)/90 * 90;
switch (orientation) {
// set params and orientation
}
ImageButton ibu = (ImageButton) findViewById(R.id.button0);
ibu.setRotation(orientation);
ibu = (ImageButton) findViewById(R.id.button1);
ibu.setRotation(orientation);
// and so on
} catch (Exception e) {
}
}
};
现在我的问题:是否有可能以同样的方式对话旋转的按钮?此刻,它们以横向显示,因为我将此活动的设备方向设置为横向。例如,当用户将手机旋转至肖像并单击button1时,对话框将显示为错误,因为它未旋转。
非常感谢