每天学一点 每天进步一点点

 每天进步一点点

 

 surfaceView  按返回键  回来的时候会重新运行一次构造方法

   按Home 不会重新运行

onKeyDown      需要先调用setFocusable(true) 获得焦点,否则按键无效果

 onTouchEvent()   返回值的时候 需要把系统的 return super.onTouchEvent(event);

                                                                          改成              return true

   转载 himi

 

                                                      这里讲下如何禁止横屏和竖屏切换!

 

在某些游戏中我们可能需要禁止横屏和竖屏切换,其实实现这个要求很简单,只要在

AndroidManifest.xml 里面加入这一行 android :screenOrientation="landscape "(landscape 是横向,portrait 是纵向)。

在android中每次屏幕的切换动会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activity再次Create的时候载入配置。在activity加上android:configChanges="keyboardHidden|orientation"属性,就不会重启activity.而是去调用onConfigurationChanged(Configuration newConfig). 这样就可以在这个方法里调整显示方式. 

 

MainActivity中:

 

 

view plain copy to clipboard print ?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. public void onConfigurationChanged(Configuration newConfig) {  
  2.         try {  
  3.             super.onConfigurationChanged(newConfig);  
  4.             if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {  
  5.                 Log.v("Himi""onConfigurationChanged_ORIENTATION_LANDSCAPE");  
  6.             } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {  
  7.                 Log.v("Himi""onConfigurationChanged_ORIENTATION_PORTRAIT");  
  8.             }  
  9.         } catch (Exception ex) {  
  10.         }  
  11.     }  

public void onConfigurationChanged(Configuration newConfig) { try { super.onConfigurationChanged(newConfig); if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { Log.v("Himi", "onConfigurationChanged_ORIENTATION_LANDSCAPE"); } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { Log.v("Himi", "onConfigurationChanged_ORIENTATION_PORTRAIT"); } } catch (Exception ex) { } } 

 

 

AndroidManifest.xml中:

 

 

view plain copy to clipboard print ?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.himi" android:versionCode="1" android:versionName="1.0">  
  4.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  5.         <activity android:name=".MainActivity" android:label="@string/app_name"  
  6.             android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation">  
  7.             <intent-filter>  
  8.                 <action android:name="android.intent.action.MAIN" />  
  9.                 <category android:name="android.intent.category.LAUNCHER" />  
  10.             </intent-filter>  
  11.         </activity>  
  12.     </application>  
  13.     <uses-sdk android:minSdkVersion="4" />  
  14. </manifest>

 

你可能感兴趣的:(职场,休闲,标签是什么?)