Eros Live
          Find the Way
          posts - 15,comments - 0,trackbacks - 0

          1.獲取屏幕的分辨率

          在 Activity 里使用如下代碼,寬度和高度的單位是像素

          Display display = getWindowManager().getDefaultDisplay();
          int screenWidth = display.getWidth();
          int screenHeight = display.getHeight();

          2.繪制文本

          使用 FontMetrics 類

          參考

          http://www.javaeye.com/topic/474526

          3.禁止自動(dòng)橫豎屏切換

          在AndroidManifest.xml的Activity節(jié)點(diǎn)加入如下屬性

          android:screenOrientation="portrait"

          portrait是縱向,landscape是橫向

          4.Resources and Assets

          無(wú)論是使用Res\raw還是使用Asset存儲(chǔ)資源文件,文件大小UNCOMPRESS限制為1MB

          參考

          http://wayfarer.javaeye.com/blog/547174

          5.SDK 1.6 新增加SD卡寫入權(quán)限

          在AndroidManifest.xml加入以下代碼

          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

          SDK1.6之前的項(xiàng)目自適應(yīng),無(wú)需此權(quán)限也可以寫入SD卡。

          6.在eclipse中查看Android Framework源代碼

          代碼下載

          1. SDK 1.5 http://www.box.net/shared/16au19tqlp
          2. SDK 1.6 http://www.box.net/shared/dh4dr9ir7j
          3. SDK 2.2 http://www.box.net/shared/dic2t0blj1

          參考

          http://www.javaeye.com/topic/534010

          7.給View注冊(cè)ContextMenu

          void setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)

          Register a callback to be invoked when the context menu for this view is being built.

          8.給Preference設(shè)置Intent

          void setIntent(Intent intent)

          Sets an Intent to be used for startActivity(Intent) when this Preference is clicked.

          9.包含CheckBox的ListView

          ListView item中加入checkbox后onListItemClick 事件無(wú)法觸發(fā)。
          原因:checkbox的優(yōu)先級(jí)高于ListItem于是屏蔽了ListItem的單擊事件。
          解決方案:設(shè)置checkbox的android:focusable="false"

          10.取得當(dāng)前的Locale

          Locale locale = context.getResources().getConfiguration().locale;

          11.使用android.text.format.Time類代替java.util.Calendar類

          The Time class is a faster replacement for the java.util.Calendar and java.util.GregorianCalendar classes. An instance of the Time class represents a moment in time, specified with second precision. It is modelled after struct tm, and in fact, uses struct tm to implement most of the functionality.

          12.調(diào)整WebView字體大小

          WebView.getSettings().setDefaultFontSize()
          WebView.getSettings().setDefaultZoom()

          13.View Animation總結(jié)

          參考

          14.檢查網(wǎng)絡(luò)狀態(tài)

          public static boolean isNetworkAvailable(Context context) {
              ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo info = cm.getActiveNetworkInfo();
              
              return (info != null && info.isConnected());
          }
           
           
          public static boolean isWifiConnected(Context context) { 
              return getNetworkState(context, ConnectivityManager.TYPE_WIFI) == State.CONNECTED;
          }
           
          public static boolean isMobileConnected(Context context) {
              return getNetworkState(context, ConnectivityManager.TYPE_MOBILE) == State.CONNECTED;
          }
           
          private static State getNetworkState(Context context, int networkType) {
              ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
              NetworkInfo info = cm.getNetworkInfo(networkType);
              
              return info == null ? null : info.getState();    
          }

          需要加入權(quán)限

          <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

          15.Parse JSON String

          參考

          1. http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
          2. http://wiki.fasterxml.com/JacksonInFiveMinutes
          3. http://stackoverflow.com/questions/2818697/sending-and-parsing-json-in-android

          16.設(shè)置EditText的輸入模式

          url, password, email, 電話鍵盤等

          設(shè)置 android:inputType 屬性

          17.Crash Report

          1. http://code.google.com/p/acra/
          2. http://code.google.com/p/android-send-me-logs/

          18.用戶解鎖消息

          android.intent.action.USER_PRESENT

          只能在代碼里注冊(cè)Receiver

          19.屏幕消息

          android.intent.action.SCREEN_ON

          android.intent.action.SCREEN_OFF

          只能在代碼里注冊(cè)Receiver

          posted on 2010-06-29 13:22 Eros 閱讀(503) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 临江市| 临夏县| 樟树市| 宁海县| 邢台县| 胶南市| 舟山市| 广州市| 泊头市| 隆回县| 宣威市| 德令哈市| 齐齐哈尔市| 剑阁县| 皮山县| 会理县| 大关县| 喀喇| 霍城县| 晋州市| 潼关县| 唐河县| 大余县| 博客| 白银市| 桑植县| 灵宝市| 两当县| 民县| 剑川县| 龙岩市| 都兰县| 涟水县| 永登县| 阿城市| 怀远县| 天等县| 大足县| 吴忠市| 阿拉善右旗| 抚松县|