Android Screen Orientation

Code: Default | Auth: 03cd82

Bạn muốn thiết lập ứng dụng hoạt động theo chiều dọc hoặc ngang màn hình thì dựa vào thuộc tính orientation của activity.

Thiết lập hướng màn hình cho activity bằng AndroidMainifest.xml

Bạn cần khai báo trong thuộc tính của thẻ <activity> nhé.

android:screenOrientation="portrait"  là hướng dọc

android:screenOrientation="landscape"  là hướng ngang

Cú pháp chung như sau:

<activity android:name="package_name.Your_ActivityName"  
      android:screenOrientation="orirntation_type">  
</activity>

Ví dụ hướng xoay ngang màn hình:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.spx.myapp01">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_may_cay"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_may_cay"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Xoay ngang màn hình

Mặc định nếu không thiết lập gì thì activity sẽ hiển thị theo hướng dọc màn hình.