Activity啓動模式
-
standard(不查,直接onCreate)
-
single top(先查詢棧頂)
-
single task(先查詢整個返回棧)
-
single instance
UI控件
TextView
- 文字的對齊方式:android:gravity(指文字在控件內部的對齊方式)
Button
- 添加監聽:setOnClickListener()
EditText
-
提示性文字:Android:hint
-
規定行數:Android:maxLines(單行的話,如果文字過多,EditText的寬度會被拉伸)
ImageView
-
指定圖片:Android:src
-
動態更改圖片:ImageView.setImageResource(R.drawable…);
ProgressBar(進度條)
-
改變進度條格式(圓形、直線等):style
-
設置最大值:Android:max(例:100),在代碼中可以獲取當前進度:ProgressBar.getProgress(),同樣,也可以對其進行設置
AlertDialog
- 通過AlertDialog.Builder創建實例
ProgressDialog(進度條對話框)
- 使用方法類似AlertDialog
四種基本佈局
LinearLayout
-
排列方向:android:orientation (vertical|horizontal)
-
對其方式:android:layout_gravity(指控件在佈局中的對齊方式)
-
權重:android:layout_weight(適配手機屏幕方面比較適用)使用此參數,一般寬度或者高度指定成0dp
RelativeLayout
-
相對於父佈局:android:layout_alignParentTop…
-
相對於其他控件:android:layout_above…
幀佈局(FrameLayout)
- 所有控件默認在左上角
百分比佈局
-
爲FrameLayout 和RelativeLayout進行擴展,時期能夠以比例進行佈局
-
app:layout_widthPercent=50%
自定義控件
-
引入自定義佈局:
-
<com.example…/>
ListView
-
適配器:Adapter ,常用的ArrayAdapter。通過適配器將數據傳遞給ListView。其中適配器中需要傳入泛型。
-
一般需要爲ListView中的子項新建佈局文件,例如:fruit_item.xml
-
自定義適配器,重寫getView()。
-
獲取泛型實例用getItem(position)??position怎麼獲取的
-
通過LayoutInflater的inflate()方法加載到父佈局中。(注:第三個參數要求爲false)