zoukankan      html  css  js  c++  java
  • 监听屏幕旋转事件

    1.声明activity要捕获的事件类型

    <activity
      
    android:name="com.funcoding.main.MainActivity"
      
    android:label="@string/app_name"   android:configChanges="orientation|screenSize"/>

    这里一定要声明Android:configChanges属性,该属性规定了我们可以在程序中捕获到的事件类型,多个事件类型用|分隔。

    如果这里没有orientation,那么我们再程序中是无法捕获到屏幕改变的事件的。targetSdkVersion>13,还需要加入
    android:configChanges="orientation|screenSize"

    2.重写Activity中的onConfigurationChanged方法

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Log.i("", "HORIZONTAL");
      } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        Log.i("", "VERTICALf");
      }
    }
  • 相关阅读:
    HTML标签(二)
    HTML 表单
    HTML列表
    HTML表格
    Critical Section Problems
    Stack, Queue and Priority Queue
    Introduction to Dynamic Set
    Introduction to Divide-and-Conquer
    Sorting Algorithms Overview
    Python学习笔记(三)数据类型
  • 原文地址:https://www.cnblogs.com/xingfuzzhd/p/3449246.html
Copyright © 2011-2022 走看看