一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久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资源站 | 国产一区二区三区久久久久久久久 | 亚洲一区二区av | 中文字幕在线一区 | 日韩一区二区免费视频 | 国产精品精品久久久 | 久久精品国产精品青草 | 99reav| 欧美福利一区 | 精品国产乱码一区二区三区 | 国产一区91精品张津瑜 | 国产aa | 国产电影一区二区 | 国产精品亚洲第一区在线暖暖韩国 | 日本三级黄视频 | 亚洲第一在线 | www.午夜 | 四虎影院一区二区 | 在线高清免费观看视频 | 欧美高清视频一区 | 国产区在线观看 | 色资源站 | 日本精品在线一区 | 欧洲精品视频一区 | 欧美精品片 | 久久国产区 | 精品日韩 | 天天综合永久 | 日韩毛片免费视频 | 在线精品观看 | 日韩欧美国产一区二区三区 | 欧美一级片在线 | 在线午夜 | 91麻豆精品国产91久久久久久 | 久久久久国产 | 就操在线| 看羞羞视频|