Android应用应该使用被以一种简洁的文件结构组织,使你的代码更容易阅读。此外,合理的代码以及类命名规则是非常重要的,以确保你的代码整洁易于维护
Naming Convention
Java Code
| Type | Example | Description |
|---|---|---|
| Variable | incomeTaxRate | All variables should be camel case |
| Constant | DAYS_IN_WEEK | All contants should be all uppercase |
| Method | convertToEuroDollars | All methods should be camel case |
| Parameter | depositAmount | All parameter names should be camel case |
For Android Classes
| Name | Convention | Inherits |
|---|---|---|
| Activity | CreateTodoItemActivity | AppCompatActivity,Activity |
| List Adapter | TodoItemsAdapter | BaseAdapter,ArrayAdapter |
| Database Helper | TodoItemsDbHelper | SQLiteOpenHelper |
| Network Client | TodoItemsClient | N/A |
| Fragment | TodoItemDetailFragment | Fragment |
| Service | FetchTodoItemService | Service,IntentService |
Android Folder Structure
- com.example.myapp.activities - 包含所有的activities
- com.example.myapp.adapters - 包含所有基本的adapter
- com.example.myapp.models - 包含所有的数据模型
- com.example.myapp.network - 包含所有的网络代码
- com.example.myapp.fragments - 包含所有的fragment
- com.example.myapp.utils - 包含有的帮助代码
- com.example.myapp.interfaces - 包含所有的接口