検索を試みましたが、この問題の解決策が見つかりませんでした。 固定の横向きのカメラアプリケーションがあります。 orientationEventListenerは、すべてのマイボタンを適切に回転させます。ただし、ダイアログや警告ダイアログを表示するボタンがいくつかあり、これらのダイアログは回転しません。ここで 固定デバイス方向以外のDialogと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 MainActivity
に関連する短縮コードは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) {
}
}
};
今、私の質問:それはボタンと同じようにダイアログを回転させることは可能ですか?現時点では、私はこのアクティビティのデバイス方向をランドスケープに設定しているので、ランドスケープで表示されます。例えば、ユーザが電話機をポートレートに回転させてボタン1をクリックすると、回転していないため、ダイアログが正しく表示されません。