How to set device wide screen orientation

by Michel » Thu, 30 Jul 2009 01:21:04 GMT


Sponsored Links
 Hi androids,

This is my first message over here and I'm a starting android
developer so please be patient. Here's my case; I'm trying to create a
simple program that sets the device's screen orientation by the press
of a button. It's quite easy to set and change the orientation for the
current activity, but I want to set and keep the setting until the
button is pressed again like when the keyboard is slide out and back
in on a G1 or by the movementsensor.

I started with using the setRequestedOrientation() but I quickly found
that's only for the current activity, as soon is I close the activity
the screen returns to it's original state. I then found that it's
possible to set orientation with updateConfiguration()

Configuration config = new Configuration();
config.orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
getResources().updateConfiguration(config, getResources
().getDisplayMetrics());

but this doesn't seem to have any effect for what soever.

I've spent hours and hours googling for possible solutions but I'm
completely stuck and the only option I found was to emulate the
keyboard slide out and in, but besides the fact that I wouldn't know
how, that seems a bit of a big solution for what seems to be a simple
task.
I thought this would be easy (and maybe it is), can somebody help me
out or point me in the right direction?

Thanks in advance,
Michel

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Error When Using a Listener

Hi all,

first of all, let me introduce my self. My name is Teguh, currently
I'm new to android and trying to develop an application in android.
At the moment I found an issue while using a listener..

code issue : (this code will generate an error when launching the
application)

public class Sudoku extends Activity implements OnClickListener{
         private static final String TAG = "Sudoku";

        @Override
        public void onCreate(Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                //Set up click listeners for all the buttons
                View continueButton = findViewById(R.id.continue_button);
                continueButton.setOnClickListener(this);
                View newButton = findViewById(R.id.new_button);
                newButton.setOnClickListener(this);
                View aboutButton = findViewById(R.id.about_button);
                aboutButton.setOnClickListener(this);
                View exitButton = findViewById(R.id.exit_button);
                exitButton.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
                // TODO Auto-generated method stub
                switch (v.getId()){
                case R.id.about_button:
                        Intent i = new Intent(this, About.class);
                        startActivity(i);
                        break;
                }
        }
}

code OK: (i removed the listener, and running successfully when
initialize)

public class Sudoku extends Activity implements OnClickListener{
         private static final String TAG = "Sudoku";

        @Override
        public void onCreate(Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
        }

        @Override
        public void onClick(View v) {
                // TODO Auto-generated method stub
                switch (v.getId()){
                case R.id.about_button:
                        Intent i = new Intent(this, About.class);
                        startActivity(i);
                        break;
                }
        }
}

-----------------------------
Does anybody know what was happened to the code?
the error comes in initialize mode of this application.

Thank you very much for all of you attention.

-- 

2. Layout Scaling

Hello,

I would like to know that is there any way to scale the layout so that
activity/application's UI fits in to provided rendering area?

I come across with the WindowManager.Layout.FLAG_SCALED in SDK but
don't know which is the most appropriate class in Android Framework to
use it?

Could anyone please give some insight on this?

Thank you,
Sanjay

-- 

3. Kejadian Ajaib Pas Charge Milestone.

4. About Image taken time in Media Scanner.

5. How to add new resources subfolder in Eclipse?

6. How to fill remained available space if i want to put a button to bottom?

7. Text from configuration to widget