一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久99深爱久久99精品_亚洲一区二区三区四区五区午夜_日本在线观看一区二区

Android 屏幕方向示例含代碼

Android 屏幕方向示例

屏幕方向是activity元素的屬性。愛掏網 - it200.comAndroidActivity的方向可以是縱向、橫向、傳感器、未指定等。愛掏網 - it200.com您需要在AndroidManifest.xml文件中定義它。愛掏網 - it200.com

語法:

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

示例:

<activity android:name=" example.javatpoint.com.screenorientation.MainActivity"  
     android:screenOrientation="portrait">  
</activity>
<activity android:name=".SecondActivity"  
     android:screenOrientation="landscape">  
</activity>

屏幕方向屬性的常見取值如下:

描述
未指定 這是默認值。愛掏網 - it200.com在這種情況下,系統選擇方向。愛掏網 - it200.com
縱向 高度大于寬度
橫向 寬度大于高度
傳感器 方向由設備方向傳感器確定。愛掏網 - it200.com

在這個示例中,我們將創建兩個不同屏幕方向的Activity。愛掏網 - it200.com第一個Activity(MainActivity)將是“縱向”方向,第二個Activity(SecondActivity)將是“橫向”方向類型。愛掏網 - it200.com

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>  
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.screenorientation.MainActivity">  


    <Button  
        android:id="@+id/button1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginBottom="8dp"  
        android:layout_marginTop="112dp"  
        android:onClick="onClick"  
        android:text="Launch next activity"  
        app:layout_constraintBottom_toBottomOf="parent"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.612"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toBottomOf="@+id/editText1"  
        app:layout_constraintVertical_bias="0.613" />  

    <TextView  
        android:id="@+id/editText1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_centerHorizontal="true"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="124dp"  
        android:ems="10"  
        android:textSize="22dp"  
        android:text="This activity is portrait orientation"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.502"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent" />  
</android.support.constraint.ConstraintLayout>  

Activity類

package example.javatpoint.com.screenorientation;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button1=(Button)findViewById(R.id.button1);
    }
    public void onClick(View v) {
        Intent intent = new Intent(MainActivity.this,SecondActivity.class);
        startActivity(intent);
    }
}

activity_second.xml

<?xml version="1.0" encoding="utf-8"?>  
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.screenorientation.SecondActivity">  

    <TextView  
        android:id="@+id/textView"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="180dp"  
        android:text="this is landscape orientation"  
        android:textSize="22dp"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.502"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent" />  
</android.support.constraint.ConstraintLayout>  

SecondActivity類

package example.javatpoint.com.screenorientation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

    }
}

AndroidManifest.xml

在AndroidManifest.xml文件的activity中添加screenOrientation屬性并提供其屏幕方向。愛掏網 - it200.com在這個例子中,我們為MainActivity提供”portrait”方向,為SecondActivity提供”landscape”方向。愛掏網 - it200.com

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

    <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="example.javatpoint.com.screenorientation.MainActivity"  
            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=".SecondActivity"  
            android:screenOrientation="landscape">  
        </activity>  
    </application>  

</manifest>  

輸出:

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論0 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 视频二区 | 中文字幕在线一区 | av天空 | 午夜视频在线 | 久久久久久a| 国产在线精品一区二区三区 | 国产高清在线精品一区二区三区 | 国产色99精品9i | 日韩成人在线视频 | 一级黄色片在线免费观看 | 天堂av中文在线 | 一区二区免费在线视频 | 免费的日批视频 | 欧美日韩高清在线一区 | 人人九九精| 丝袜毛片| 亚洲性爰 | 成人av在线网站 | 久久草在线视频 | 欧美日韩一区在线播放 | 一区二区在线 | 国产精品久久久久久久岛一牛影视 | 亚洲精品亚洲人成人网 | 久久免费精品 | 国产成人精品免费视频 | 一区二区三区在线免费观看视频 | 成人在线小视频 | 午夜日韩 | 亚洲欧美日韩在线 | 天天看天天操 | 国产精品国产三级国产aⅴ原创 | 99热电影| 日韩中文字幕在线不卡 | 成人欧美一区二区三区黑人孕妇 | 影音先锋亚洲资源 | 中文字字幕在线中文乱码范文 | 手机av免费在线 | 91麻豆精品国产91久久久更新资源速度超快 | 精品国产18久久久久久二百 | 欧美美乳 | 精品久久久久久久久久久久久久 |