欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android App獲取屏幕旋轉角度的方法

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

本文實例為大家分享了Android App獲取屏幕旋轉角度的具體代碼,供大家參考,具體內容如下

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

二、測試代碼

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í)行效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • android語音即時通訊之錄音、播放功能實現代碼

    android語音即時通訊之錄音、播放功能實現代碼

    這篇文章主要為大家詳細介紹了android語音即時通訊之錄音、播放功能的實現代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android組件實現列表選擇框功能

    Android組件實現列表選擇框功能

    android提供的列表選擇框(Spinner)相當于web端用戶注冊時的選擇下拉框,比如注冊候選擇省份城市等。這篇文章主要介紹了Android組件實現列表選擇框功能,需要的朋友可以參考下
    2017-02-02
  • Android 提交或者上傳數據時的dialog彈框動畫效果

    Android 提交或者上傳數據時的dialog彈框動畫效果

    我們在使用支付寶支付的時候會看到類似這種彈框動畫效果,下面通過實例代碼給大家分享android 提交或者上傳數據時的彈框動畫效果,感興趣的的朋友參考下
    2017-07-07
  • Android在多種設計下實現懶加載機制的方法

    Android在多種設計下實現懶加載機制的方法

    這篇文章主要介紹了Android在多種設計下實現懶加載機制的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-06-06
  • Android 開發(fā)仿簡書登錄框可刪除內容或顯示密碼框的內容

    Android 開發(fā)仿簡書登錄框可刪除內容或顯示密碼框的內容

    本文通過實例代碼給大家分享android開發(fā)中模仿簡書登錄框可刪除內容或顯示密碼框的內容,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2016-12-12
  • Android實現的仿淘寶購物車demo示例

    Android實現的仿淘寶購物車demo示例

    這篇文章主要介紹了Android實現的仿淘寶購物車demo示例,結合實例形式分析了Android購物車的功能、布局及邏輯實現技巧,需要的朋友可以參考下
    2016-07-07
  • Android 仿微信數字鍵盤

    Android 仿微信數字鍵盤

    大部分的金融App會對默認的數字鍵盤進行處理,以實現自定義的數字安全鍵盤。基于此,本文對對微信數字鍵盤樣式進行了仿寫,實現了一套自定義的數字安全鍵盤(支持隨機數字分布)。
    2021-05-05
  • Android消息通知欄的實現方法介紹

    Android消息通知欄的實現方法介紹

    本篇文章是對Android消息通知欄的實現方法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • Android使用surfaceView自定義抽獎大轉盤

    Android使用surfaceView自定義抽獎大轉盤

    這篇文章主要為大家詳細介紹了Android使用surfaceView自定義抽獎大轉盤,熟練掌握SurfaceVie實現抽獎大轉盤,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android自定義Dialog實現通用圓角對話框

    Android自定義Dialog實現通用圓角對話框

    這篇文章主要為大家詳細介紹了Android自定義Dialog實現通用圓角對話框,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11

最新評論