disable rotation programmatically?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

disable rotation programmatically?

Postby danguyf » Sat Jun 13, 2009 4:20 pm

I know that I can specify a rotation in AndroidManifest.xml with android:screenOrientation, but is there any way to set it programmatically?

I want to lock onto the orientation that the app starts in, whichever it is. I can retrieve the orientation onCreate(), but can't figure out how to set it.

Thank you.
danguyf
Freshman
Freshman
 
Posts: 6
Joined: Mon Jun 08, 2009 5:49 pm

Top

Postby Grey Goo » Sat Jun 13, 2009 11:22 pm

I just got on to ask that same question.

I'm assuming you want have your program only run in one orientation even when the device is rotated?

I'll post back here if I find anything.
Grey Goo
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon May 11, 2009 3:56 am

Postby Emmanuel7 » Sun Jun 14, 2009 1:54 am

I think you should add this line in the activity manifest :
android:configChanges="keyboardHidden|orientation"

And take the decision by overriding the "public void onConfigurationChanged(Configuration newConfig)" method.

Hope it helps,
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby danguyf » Mon Jun 15, 2009 6:11 pm

That sounds sensible. I appears that when I override onConfigurationChanged() it rotates anyway, though.

I would save the original orientation and then set it back onConfigurationChanged(), but that goes right back to my original question: How do I specify a rotation?
danguyf
Freshman
Freshman
 
Posts: 6
Joined: Mon Jun 08, 2009 5:49 pm

Postby Grey Goo » Mon Jun 15, 2009 7:35 pm

I never found a way to have it lock into one rotation, for my solution I just had everything pause when it was in portrait and said "paused, go to landscape to continue" or something similar.

I'm not sure if that will help for your program/game, but that's the only solution I came up with for mine.
Grey Goo
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon May 11, 2009 3:56 am

Postby Mr_Tremor » Tue Jun 16, 2009 3:34 am

You can set your rotation with

setRequestedOrientation(0);

0=Landscape

for other orientations see

http://developer.android.com/reference/android/R.attr.html#screenOrientation
Mr_Tremor
Developer
Developer
 
Posts: 26
Joined: Tue Jun 02, 2009 6:35 pm

Top

Postby Grey Goo » Tue Jun 16, 2009 6:36 pm

Mr_Tremor wrote:You can set your rotation with

setRequestedOrientation(0);

0=Landscape

for other orientations see

http://developer.android.com/reference/android/R.attr.html#screenOrientation


Thanks a lot, works perfect. :D
Grey Goo
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon May 11, 2009 3:56 am

Postby danguyf » Tue Jun 16, 2009 6:46 pm

Mr_Tremor wrote:You can set your rotation with

setRequestedOrientation(0);

0=Landscape

for other orientations see

http://developer.android.com/reference/android/R.attr.html#screenOrientation


Perfect! Thank you so much.
danguyf
Freshman
Freshman
 
Posts: 6
Joined: Mon Jun 08, 2009 5:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests