Зафиксируйте приложение для телефона Android в портрет

StackOverflow https://stackoverflow.com/questions/5044544

Вопрос

Может кто-нибудь сказать мне, как заблокировать свое приложение в портретный режим?Это простая конфигурация в файле манифеста?

Это было полезно?

Решение

Yes. Add android:screenOrientation="portrait" to the manifest under your main activity.

<activity android:name=".yourActivity" android:screenOrientation="portrait"... />

Другие советы

Yes! It's an attribute of the activity tag:

<activity android:name=".yourActivity" android:screenOrientation="portrait" ... />

Also, you may have to add the following to your activity element:

android:configChanges="keyboardHidden"

That way, the OS won't change the orientation when the user opens a sliding keyboard.

None of these answers worked on my system but I did find the following worked perfectly for a simple app that I developed:

Within MainActivity.java add:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

to onCreate ()

This is mine:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

I know that it is not (always) best practice locking orientation, but in special circumstances it is valid and I only want this temporarily while I continue developing.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top