5.9

1.UI 的理解|
全稱user interface,意爲: 用戶界面UI 由View 和ViewGroup 組成
View 類是所有視圖(包括ViewGroup)的根基類
View在屏幕上佔據一片矩形區域,並會在上面進行內容繪製
ViewGroup 包含一些View 或ViewGroup,用於控制子View 的佈局
1).TextView: 文本視圖
<TextView
android:id='@+id/tv_test1_message //指定idandroid:layout_width='match_parent' //寬度android:layout_height='wrap_content ' 高度
android:text='這是TextView的內容“// 文本
android :textColor='#ff0000' // 文本顏色
android :textSize =“20sp' /> // 字體大小
2).EditText: 可編輯的文本視圖
//默認提示文本
android:hint='請輸入手機號“
android:in putType='phone'> '//輸入數據類型限定
4). TImageView : 圖片視圖
android:background='@drawable/ic_ launcher' //背景圖片
android:src='@android:drawable/ic_ media_ play'/>//前景圖片
//設置前景圖片
public void setlmageResourc e(int resld)
//設置背景圖片
public void setBackgroundResource(int resid)
5). CheckBox: 多選框
WWWWWWWWW
android:checked='true'/> //標識默認是否勾選
//判斷當前是否勾選boolean isChecked()//設置CheckBox是否勾選
void setChecked(boolean checked)//設置選中狀態改變的監聽
void setOnCheckedChangeListener(Onheckedhangelistene listener)
6). RadioGroup/RadioButton: 單選框
<RadioGroup
android:id='@+id/rg_test1_sex'
android:layout_width='fill_parent'
android:layout_height='wrap_content'
android:orientation='horizontal >
<RadioButton
android:id='@+id/rb_test1_male
android:layout_width='wrap_content'
android:layout_height='wrap_content'
android:text=' 男' />
android:id='@+id/rb_test1fele
android :layout_width ='wrap_co ntent'
android:layout_height='wrap_content'
android:checked='true'
android:text='女' />
</RadioGroup>
2.2.菜單Menu
1).0ptionMenu 可
1.如何觸發Menu 的顯示?點擊menu 鍵
如何向Menu 中添加MenuItem?重寫onCreateOptionMenu ()menu.add () 或者加載菜單文件
3. 選擇某個MenuItem 時如何響應?
重寫on0ptionsItemSelected (),根據itemId做響應
2).ContextMenu
1.如何觸發Menu 的顯示?
長按某個視圖
view.setOnCreateContextMenuListener(this)2.如何向Menu中添加MenuItem?重寫onCreateContextMenu()menu. add()
3.選擇某個MenuItem時如何響應?
重寫onContextItemSelected (),根據itemId 做響應
進度條
2.3.
1.ProgressBar
圓形
//默認爲圓形進度條
<ProgressBar
android:id='@+id/pb_testaing
android :I ayout_width=' wra p_co nte nt'
android :layout_height ='wrap_content' />
b.水平
<ProgressBar
android:id='@+id/pb_ .test3_ loading2'
style='?
androidattrprogressBarStyleHorizontal' //水平進度條
android:kyout_ width='match_ parent'
android:layout_ height=' 'wrap_ .content'
android:progress='2' //當前進度,默認爲0android:max='10'/> //最大進度,默認爲100
ProgressBar
void setProgress(int Progress): 設置當前進度int getProgress(): 得到當前進度
void setMax(int max): 設置最大進度int getMax() :設置或得到最大進度
View
void setVisibility(int visibility): 設置視圖的可見性View.VISIBLE :標識可見
View.INVISIBLE :標識不可見,但佔屏幕空間View.GONE :標識不可見,也不佔屏幕空間
2).SeekBar
<SeekBar
android:id='@+id/sb_test3_prgre
android:layout_width='match_parent'
android:layout_height='wrap_content' />
SeekBar:
setOnSeekBarChangeListener(OnSeekBarhangeistener I): 設置改變的監聽OnSeekBarChangeListener:onProgressChanged(SeekBar seekBar,intprogress,boolean fromUser) :進度改變
onStartTrackingTouch(SeekBar seekBar): 按下滑桿
onStopTrackingTouch SeekBa r seekBar): 從滑桿離開
2). AlertDialog
a.一般的
AlertDialog :
show() :顯示警告框
沒有公開的構造方法,只能通過其內部類Builder來創建
AlertDialog.Builder :
create() :創建AlertDialog對象
show() :創建AlertDialog對象,同時將其顯示出來
setTitle(CharSequence title) :設置標題
setMessage(CharSequence message) :設置內容
setPositiveButton(String text,OnClickListener listener) :設置正面按鈕
setNegativeButton(String text,OnClickListener listener): 設置負面按鈕
dismiss() :移除dialog
b.自定義佈局的
動態加載佈局文件得到對應的View 對象
View inflgte(Context context,int resource,ViewGroup root) :動態加載佈局得到View
設置View
DialogBuilder :
setView(View view): 設置Dialog中的視圖
b.水平迸度
ProgressDialog(Context context) :枸造方法
setProgressStyle(int style)沒置祥式
ProgressDialog.STYLE_ HORIZONTAL :氷平迸度條祥式
2).根據id 查找View對象
查找當前界面中的View 對象:
findViewById(id)
b.查找某個View 對象的子View: view.findViewById(id)
3).更新視圖
a.不能在分線程直接更新UI :
toast 不能在分線程顯示,
但ProgressDialog可以在分線程更新
b.長時間的工作只能放在分線程執行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章