Reputation: 11
I tried using search but didn't find a solution for this problem. I have a camera application with fixed landscape orientation. An orientationEventListener properly rotates all my buttons. There are, however, some buttons that shall show a dialog or alertdialog and these dialogs are not rotated. Here is the relevant shortened code in MainActivity
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
and
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 is a linearLayout containing TextViews and ImageViews.
The rotation of buttons works like this:
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) {
}
}
};
Now my question: Is it possible to rotate the dialogs in same manner as the buttons? At the moment, they are displayed in landscape since I set device orientation for this Activity to landscape. When user for example rotates the phone to portrait and clicks button1, dialog will be shown wrong because it is not rotated.
Many thanks
Upvotes: 1
Views: 1458
Reputation: 11
Ok so I resolved the issue by creating separate Activity for each dialog. The problem is now, when the new foreground dialog Activity is rotated, the background Activity will rotate as well! Can I somehow set the background Activity orientation when I rotate foreground Activity?
Upvotes: 0