質問

たいのですが無効モードのビュー私のAndroidアプリ?

役に立ちましたか?

解決

追加 android:screenOrientation="portrait" の活動のAndroidManifest.xml.例えば:

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

編集:この組合せたブレンデッドラーニング人気の回答させていただき有罪で押し付けようとしていると画像とは、ほとんどに最適なソリューションを提供する問題で頻繁に適用。
の主要注意強肖像:

  • こなから免れるお考えなければいけない活動 ライフサイクルイベントを適切に保存/復元す。たくさんあり 以外にもいろいろアプリの回転可能なトリガーの活動 破壊/レクリエーションを含むを得ないような複合加工.ありませんのショートカット;学習用のバンドルと retainInstance の姿です。
  • 意することはかなり均一にiPhoneが一部のデバイスが肖像を明確に人気。時にユーザーのデバイスとハードウェアキーボードゲームパッドa laのNvidiaシールド、 Chromebooks, は、 foldables, または サムスンDeX, 力画像できるアプリの経験のいずれかの制限または巨大な使い勝手で生活することができます。例えばシェアする画面でユーザーさんが強いUXの引数が負の経験のための支援その他、オリエンテーション、きょうさせることはできません。いつものように"このジャーアプリの特定のモデルのタブレットについて、一定のハードドックがあります。"

ほとんどのアプリと同じように、電話センサー、ソフトウェア、物理的形態は自己の判断はどのようにユーザーが知りたいと交流するとアプリです。少しできる場合も考えていきたいと思いものであれば、満足しないデフォルトの挙動 sensor 向きをご利用の場合:

  • が主な懸念は偶発的配向変化の中の活動をお考えのデバイスのセンサおよびソフトウェアなの対応(例えば、チルト-ゲーム)の検討を支援風景や肖像画が nosensor める向きを確認して下さい。この力の景観をほとんどのタブレットや肖像画をほとんどの携帯電話が、今でもなお多くの"正常先"アプリ(一部のユーザーのようなタイプの風景softkeyboard、携帯電話は、多くのタブレットユーザーに読み込肖像すると信じましょう。
  • の場合 まだ 必要な力画像のための何らかの理由で sensorPortrait されておく方が良いかもしれないよ portrait Android2.3+;これによっ逆さまの肖像するのはタブレット。

他のヒント

私は自分のアプリの中で私が使用しているので、この記事を読んまでAndroidManifest.xmlファイルスイッチの認識していなかった。この代わります:

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);     //  Fixed Portrait orientation
あなたはこのようなあなたの活動を宣言ここで、

マニフェストファイルにこのandroid:screenOrientation="portrait"を追加

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

あなたはJavaコードトライを使用して行いたい場合は、

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

あなたはsetContentViewであなたの活動のためのonCreate()メソッドを呼び出す前に。

このヘルプを願っていますし、すべてのための分かりやすい...

ここでの回答の多くは、あなたのAndroidManifest.xmlファイルに"portrait"を使用することを示唆しています。これは、良い解決策のように見えるかもしれません - しかし、マニュアルに述べたように、あなただけの景観を有することができるデバイスを選び出しています。あなたはまた、肖像画に入る(風景の中に最もよく働く)特定のデバイスを強制的に正しい向きを取得されていません。

私の提案ではなく"nosensor"を使用することです。これは、そのデフォルトの優先配向を使用するようにデバイスを残してGoogle Playでの任意の購入/ダウンロードをブロックしません、とセンサーがめちゃくちゃにあなた(NDK、私の場合は)ゲームをしないようになります。

あなたは、ユーザーの設定をしたい場合は、

そして、私はsetRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);をお勧めします。

あなたは、設定メニューから設定を変更することができます。

私は私のタイマーは、画面上の何に対応しなければならないので、これを必要とし、画面を回転すると、現在の活性を破壊します。

ちょうどあなたのマニフェストにこのような行を追加

  

アンドロイド:screenOrientation = "ポートレート"

<manifest
    package="com.example.speedtestmeter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="ComparisionActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

        <activity
            android:name="GaugeView"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

        <activity
            android:name="Resultactivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

    </application>

</manifest>   

)(のonCreateでこれを使用して活性の

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

ちょうどあなたのアクティビティタグにこの属性を追加します。

 android:screenOrientation="portrait"

あなたの代わりに、アプリケーションのすべての活動によって継承されるBaseActivityクラス(継承「活動」や「AppCompatActivity」)を作成し、より良い活動の各マニフェストエントリにオリエンテーションを追加する手間を通過したくない場合「活動」や「AppCompatActivity」は、ちょうどあなたのBaseActivityに次のコードを追加します:

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    // rest of your code......
}

あなたはのAndroidManifest.xmlでandroid:screenOrientation="sensorPortrait"を変更する必要があります。

あなたは風景モードを無効にする活動にandroid:screenOrientation="portrait"を追加します。

したい場合は無効にする Landscape mode for your android app (または単一の活動だけで追加、

android:screenOrientation="portrait" の活動タグ AndroidManifest.xml ファイルです。

のように:

<activity android:name="YourActivityName" 
    android:icon="@drawable/ic_launcher" 
    android:label="Your App Name" 
    android:screenOrientation="portrait">

を意味するものとして、プです。

たいのであればこのprogramaticallyります。Javaを利用してコードです。できるよう、以下のコードは、Javaクラスの活動をしない表示する風景モードになります。

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

あなたにとってどんな年でしたお手伝いさせていただきます。詳しくは訪問することができち 入力リンクdescriptionこちら

ビューのいくつかで向きを変更する方法

あなたが動的に実用的あなたのビューのいずれかからの向きをロックするには、このクラスを使用することができる代わりに、全体の活動の向きをロックする: -

あなたのビューを作るの の風景

OrientationUtils.lockOrientationLandscape(mActivity);

あなたのビューを作るの の肖像

OrientationUtils.lockOrientationPortrait(mActivity);

のロックを解除のオリエンテーション

OrientationUtils.unlockOrientation(mActivity);

オリエンテーションUtilのクラス

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.view.Surface;
import android.view.WindowManager;

/*  * This class is used to lock orientation of android app in nay android devices 
 */

public class OrientationUtils {
    private OrientationUtils() {
    }

    /** Locks the device window in landscape mode. */
    public static void lockOrientationLandscape(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }

    /** Locks the device window in portrait mode. */
    public static void lockOrientationPortrait(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    /** Locks the device window in actual screen mode. */
    public static void lockOrientation(Activity activity) {
        final int orientation = activity.getResources().getConfiguration().orientation;
        final int rotation = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
                .getRotation();

        // Copied from Android docs, since we don't have these values in Froyo
        // 2.2
        int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8;
        int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9;

        // Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO
        if (!(Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO)) {
            SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }

        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
            if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
            if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            }
        }
    }

    /** Unlocks the device window in user defined screen mode. */
    public static void unlockOrientation(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
    }

}

使用

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

あなたはそれぞれの活動の方向性を設定する必要があります。

<activity
                android:name="com.example.SplashScreen2"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
            </activity>
            <activity
                android:name="com.example.Registration"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
            </activity>
            <activity
                android:name="com.example.Verification"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
            </activity>
            <activity
                android:name="com.example.WelcomeAlmostDone"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
            </activity>
            <activity
                android:name="com.example.PasswordRegistration"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
            </activity>

OnCreate関数の内部クラスを追加()メソッド

 setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

は、のXamarinこれらのソリューションののC#いくつかの動作しませんを使用している場合。ここで私が働くことが分かったソリューションです。

[Activity(MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Portrait)]

クラスの上には、グローバルに適用することができない、また、他のソリューションと同様、うまく機能し、各アクティビティ・ヘッダ内に配置する必要がある。

あなたはあなたのmanifest.xmlでこれを書き込むことによって、常に縦長モードのままに、あなたの特定の活動を強制することができます。

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

また、あなたの活動ののonCreate()メソッド

に次の行を書き込むことにより、postraitモードのままにあなたの活動を強制することができます
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_layout);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

}
<android . . . >
    . . .
    <manifest . . . >
        . . .
        <application>
            <activity android:name=".MyActivity" 
                android:screenOrientation="portrait" 
                android:configChanges="keyboardHidden|orientation">
            </activity>
        </application>
    </manifest>
</android>

あなたはすべてのあなたの活動が共通の基底クラスを拡張させることなく、アプリケーション全体のためにこれを行うことができます。

トリックは、あなたのプロジェクトでのアプリケーションのサブクラスを含めることを確認する最初のものです。そののonCreate()で、あなたのアプリケーションが最初に起動したとき、あなたは活動のライフサイクルイベントの通知を受け取るためにActivityLifecycleCallbacksオブジェクト(APIレベル14+)の登録と呼ばれます。

このは、あなたのアプリ内のすべての活動を開始(または停止、または再開、または何でも)されるたびに、独自のコードを実行する機会を与えてくれます。この時点では、新しく作成された活動にsetRequestedOrientation()を呼び出すことができます。

とアプリを追加することを忘れないでください:あなたのマニフェストファイルの名前=「MyAppの」

class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();  

        // register to be informed of activities starting up
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

            @Override
            public void onActivityCreated(Activity activity, 
                                          Bundle savedInstanceState) {

                // new activity created; force its orientation to portrait
                activity.setRequestedOrientation(
                    ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
            ....
        });
    }
}

<apphome>/platform/androidディレクトリでAndroidManifest.xml(生成されたものからそれをコピー)を作成しました。 その後、活動のすべての要素にandroid:screenOrientation=portrait」を追加します。

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.co.nurture.bajajfinserv">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>


    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:screenOrientation="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

私たちは、属性やAndroid使ってポートレートや風景モードでの活動を制限することができます。screenOrientationを

私たちは私のプログラムで複数の活性を有している場合は、

は、あなたがいずれかのモードでの活動のいずれかを制限する自由を持っている、それはあなたがしたくない他人に影響を与えることはありません。

追加 android:screenOrientation="portrait"AndroidManifest.xml ファイルです。

例えば:

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

以下の内容を追加しますを表彰するプロジェクト

npm install

npmい反応ネイティブ-オリエンテーション-ロッカー

その利用マニフェストクラス、 React_Native(プロジェクトのフォルダ/ android/app/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="landscape"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

感謝です。

はkotlin同じでプログラム的

以下使用して達成することができます
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

これは私のために働いた、

AndroidManifestファイルにこのコードを追加してみてください
<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme">
        ....
        ....
        </application>

のいずれかマニフェストクラスの

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

またはプログラム

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

注:あなたはsetContentViewであなたの活動のためのonCreate()方法前にこれを呼び出す必要があります。

他の誰かを助けることを望んでは、AndroidManifest.xmlにの活動で、次の属性を使用すると、必要なすべてのです。

アンドロイド:configChanges = "方向"

だから、完全な活性ノードます:

<activity android:name="Activity1" 
    android:icon="@drawable/icon" 
    android:label="App Name" 
    android:configChanges="orientation">

最初のデバイスの配向状態に関連した活動は、onCreate方法で、現在のデバイスの向きを取得し、永遠にそれを修正する場合:

        int deviceRotation = ((WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();

        if(deviceRotation == Surface.ROTATION_0) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        else if(deviceRotation == Surface.ROTATION_180)
        {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        }
        else if(deviceRotation == Surface.ROTATION_90)
        {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        else if(deviceRotation == Surface.ROTATION_270)
        {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top