·
· 在Eclipse中開發android應用必備工具。
在Eclipse編譯IDE環境中,需安裝ADT(Android Development Tools)Plug-in,這是Android在Eclipse上的開發工具。
目前這個是最新版。
在Eclipse編譯IDE環境中,需安裝ADT(Android Development Tools)Plug-in,這是Android在Eclipse上的開發工具。
目前這個是最新版。
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.himi"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
- <uses-sdk android:minSdkVersion="4" />
- </manifest>
很明顯我在故意消耗記憶體和時間。
- /**
- * @author Himi
- * @param canvas
- */
- public void hot(Canvas canvas) {
- for (int i = 1; i < 100; i++) {
- Bitmap bmp = BitmapFactory.decodeResource(getResources(),
- R.drawable.icon);
- canvas.drawBitmap(bmp, i += 2, i += 2, paint);
- }
- }
代碼很簡單,一個是處理實體按鍵的回應時間,另一個是觸屏的回應事件、那麼這裡要說的有兩點:
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- Log.v("test", "onTouchEvent");
- bmp_y++;
- if (event.getAction() == MotionEvent.ACTION_MOVE) {
- Log.v("Himi", "ACTION_MOVE");
- } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
- Log.v("Himi", "ACTION_DOWN");
- } else if (event.getAction() == MotionEvent.ACTION_UP) {
- Log.v("Himi", "ACTION_UP");
- }
- return true;
- //return super.onTouchEvent(event);//备注1
- }
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- Log.v("test", "onKeyDown");
- bmp_x++;
- return super.onKeyDown(keyCode, event);
- }
這個例子是當你Touch Down的時候會送event進來,接著印出Log,然後呼叫super的onTouchEvent()並回傳佈林值。此時會回傳false,並且之後再也收不到Touch Move或Touch Up的event,為了要確保能收到event,必須要回傳true,所以在這裡要注意一下。
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- Log.i("ConanLog", "Event"+event.getAction());
- return super.onTouchEvent(event);
- }
AndroidManifest.xml中:
- 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) {
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.himi" android:versionCode="1" android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity" android:label="@string/app_name"
- android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-sdk android:minSdkVersion="4" />
- </manifest>