最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android App獲取屏幕旋轉(zhuǎn)角度的方法

 更新時(shí)間:2022年07月20日 12:39:29   作者:海月汐辰  
這篇文章主要為大家詳細(xì)介紹了Android App獲取屏幕旋轉(zhuǎn)角度,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android App獲取屏幕旋轉(zhuǎn)角度的具體代碼,供大家參考,具體內(nèi)容如下

一、獲取屏幕旋轉(zhuǎn)角度的方法是int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();

二、測(cè)試代碼

1、getRotation\app\src\main\java\com\example\getrotation\MainActivity.java

package com.example.getrotation;
?
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
?
import org.w3c.dom.Text;
?
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
? ? final String TAG="rotation";
? ? TextView ?mshow_rotation;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? findViewById(R.id.btn_update).setOnClickListener(this);
? ? ? ? mshow_rotation=(TextView) findViewById(R.id.show_rotation);
? ? }
?@Override
? ? public void onClick(View view) {
? ? ? ? if (view.getId() == R.id.btn_update) {
? ? ? ? ? ? int angle = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
?
? ? ? ? ? ? switch (angle) {
? ? ? ? ? ? ? ? case Surface.ROTATION_0:
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "Rotation_0");
? ? ? ? ? ? ? ? ? ? mshow_rotation.setText(Integer.toString(0)+"℃");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Surface.ROTATION_90:
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "ROTATION_90");
? ? ? ? ? ? ? ? ? ? mshow_rotation.setText(Integer.toString(90)+"℃");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Surface.ROTATION_180:
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "ROTATION_180");
? ? ? ? ? ? ? ? ? ? mshow_rotation.setText(Integer.toString(180)+"℃");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Surface.ROTATION_270:
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "ROTATION_270");
? ? ? ? ? ? ? ? ? ? mshow_rotation.setText(Integer.toString(270)+"℃");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "Default Rotation!");
? ? ? ? ? ? ? ? ? ? break;
?
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

2、布局文件activity_main.xml

<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=".MainActivity">
?
? ? <TextView
? ? ? ? android:id="@+id/show_rotation"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text=""
? ? ? ? app:layout_constraintBottom_toBottomOf="parent"
? ? ? ? app:layout_constraintLeft_toLeftOf="parent"
? ? ? ? app:layout_constraintRight_toRightOf="parent"
? ? ? ? app:layout_constraintTop_toTopOf="parent" />
? ? <Button
? ? ? ? android:id="@+id/btn_update"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="Get Rotation value"
? ? ? ? tools:layout_editor_absoluteX="145dp"
? ? ? ? tools:layout_editor_absoluteY="119dp" />
?
</android.support.constraint.ConstraintLayout>

三、執(zhí)行效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

铁岭县| 安西县| 芒康县| 察隅县| 临朐县| 桐乡市| 山东省| 丰都县| 沁水县| 巴彦淖尔市| 洞头县| 吉首市| 潼南县| 威远县| 江津市| 襄城县| 梁河县| 峨眉山市| 综艺| 宣武区| 辽源市| 松桃| 离岛区| 拜城县| 稻城县| 巫山县| 崇明县| 道真| 濮阳县| 东海县| 无锡市| 田阳县| 汤阴县| 吉林市| 怀仁县| 文登市| 台湾省| 思茅市| 辉南县| 寿宁县| 轮台县|