Android - only vertical layout

How can I make sure my app is only for vertical layout?

I tried android:screenOrientation="portrait" , but that doesn't seem like a trick.

+52
android
Mar 23
source share
8 answers

You need to add all your actions not only for one. I think you understand that the configuration for each application is wide, but it is not.

 <activity android:name=".MyActivity" android:label="My Activity" android:screenOrientation="portrait"> 

Add an ad to the activity tag in AndroidManifest for each action that is required only for the portrait.

+143
Mar 23
source share

If you want a certain group of your actions to be blocked only in PORTRAIT mode, you can choose the following method:

 public abstract class BasePortraitActivity extends Activity { @Override protected final void onCreate(Bundle state) { super.onCreate(state); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); performOnCreate(state); } protected abstract void performOnCreate(Bundle state); } 

And just BasePortraitActivity where necessary. Or just add setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); in YourActivity.onCreate() .

+17
Apr 13 '12 at 13:13
source share

you need to go to AndroidManifest.xml.

for every activity you have to insert:

 android:configChanges = "orientation" android:screenOrientation = "portrait" 

eg:

 <activity android:name=".YourActivityName" android:label="@string/app_name" android:configChanges = "orientation" android:screenOrientation = "portrait"> 

This works for one action. But there is no widespread application customization.

+10
Aug 24 '11 at 7:10
source share

In your manifest under action add this:

 <activity android:name="com.zeus.MyProject" android:screenOrientation="portrait" > 
+4
Mar 17 '13 at 22:21
source share

Add android:configChanges="keyboardHidden|orientation" to the action.

+2
Mar 23
source share

Just to confirm Pentium10 answer. I had a similar problem, and adding an android: screenOrientation = "portrait" to the tag helped.

+1
Mar 24 '10 at 1:26
source share

Android: orientation = "vertical" put this attribute in the root of the layout, try it, it can help.

+1
Mar 24 '10 at 11:34
source share

The activity is to block just in case, to block everything and just repeat this line of code in your actions.

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // Here, talk to the java does not want that the user can rotate their activity. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

or open "AndroidManisfest.xml" and add lines for portrait mode, as shown below.

  android:configChanges="orientation" android:screenOrientation="portrait"> 
+1
Jul 30 '14 at 19:27
source share



All Articles