eclipse android

1. eclipse 增加新的class
   file->new-class: 彈出的界面可以設置class name, super class, interface等


2. 在eclipse工程中增加圖片資源
   複製圖片, 然後在eclipse界面下對應目錄選擇粘帖即可
   遇到問題: 在代碼中R.drawable後沒有放入的圖片ID
   解決: 新建drawable目錄, 把圖片放到這個目錄下, 同時刪除其他目錄下的同名圖片, 然後ctrl-shift-o, 選擇自己packge的R而不是android.R, 然後OK.
         實際就是import yourpackage.R;
   說明:
   1) 圖片名必須小寫
   2) eclipse自己會import anroid.R, 很多情況下會產生混淆, 官方說明如下
      *Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially 
       when you ask Eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import 
       statements and delete them.*
      解決方法是ctrl-shift-o,修改R文件
   3) android lint是一個強大的靜態分析工具, 比如本次它就提示在不同drawable-xxx目錄下的png分辨率一致, 產生警告, 所以最後我選擇刪除其他目錄下的png
      以下是android的簡介
Android Lint是SDK Tools 16 (ADT 16)之後才引入的工具,通過它對Android工程源代碼進行掃描和檢查,可發現潛在的問題,以便程序員及早修正這個問題。
        Android Lint提供了命令行方式執行,還可與IDE(如Eclipse)集成,並提供了html形式的輸出報告。
由於Android Lint在最初設計時就考慮到了independent於IDE,所以它可以很方便的與項目中的其他自動系統(配置/ Build / 測試等)集成.
Android Lint主要用於檢查以下這些錯誤:
1、Missing translations (and unused translations)沒有翻譯的文本
2、Layout performance problems (all the issues the old layoutopt tool used to find, and more)
3、Unused resources未使用的冗餘資源
4、Inconsistent array sizes (when arrays are defined in multiple configurations)在多個配置中的數組大小不一致文件
5、Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
6、Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
7、Usability problems (like not specifying an input type on a text field)
8、Manifest errors
當然Android Lint遠遠不至檢查以上的錯誤,更多的內容請參考《Android Lint 檢查規則列表》
在Eclipse中可以在菜單Window->Preference->“Lint Eerro checking”中設置規則的檢查級別,如圖1所示。
檢查級別可以是:
Default
Fatal
Errro
Waring
Information
Ingore(即不檢查)


3. Manifest XML文件中可以修改sdk level, 似乎target sdk level 不能設置太低, 當然min sdk level可以低一些, 否則鏈接模擬器時會莫名斷開, 在android lint中會給出
   一些提示


4. 繼承自SurfaceView, 並實現runnable interface, 在surfaceCreated()內new thread()(以this爲參數)並初始化各種參數(因爲此處纔可以獲得屏幕尺寸)
   資源加載可以放在類初始化函數中


5. 選中一個類名, 然後在eclipse->Source下有菜單可以選擇父類的虛函數

6. eclipse 中有一個DDMS視圖, 其中的一個下拉菜單中有reset adb, 這個功能可以重啓adb, 避免重啓設備或eclipse
   另外調試過程中最好設法禁用手機助手等工具
   
7. powerpoint生成支持透明度的png
   導入圖片->重新着色->設置透明色->保存爲png
   
8. synchronized作爲塊同步時, 需要一個object,下面是一個簡單的方法爲synchronized準備一個參數(在初始化函數中使用)
   private Object m_LockTouch;
   
   m_LockTouch = new byte[1]; //create an object to used a lock
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章