m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

androidで向きを固定して起動する

起動するときに位置を固定して起動する

横にしてレイアウトが崩れたり内容が初期化されたくない場合

AndroidManifest.xmlを編集する
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.matsumotoshigeharu.sampleappimage" >

    <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>
    </application>

</manifest>

※activityの中に"android:screenOrientation"を追加して対応

android:screenOrientation

・landscape
横方向固定

・portrait
縦方向固定

問題

現在はこれだけですけどアクティビティによって画面の向きを変えたい場合などは他の対応が必要と思われる