27th March 老師答疑更新
-關於第三週的作業
-Handler獲取時間有可能會不準確,如果不停發送消息,刷新比較頻繁,可能會造成堵塞,以至於時間控制不準確
Timer會更準確一些
-不建議調用系統的圖片等資源,不同版本可能位值等不一樣,可能會調用不到爲空
- px, dp, sp, dip
畫分割線可以用1px
dp = dip
LayoutInflater 將xml解析爲視圖
Activity繼承於Context
獲取佈局的方式/獲得LayoutInflater實例的三種方式 (xml -> view)
LayoutInflater layoutInflater = getLayoutInflater();
getSystemService (LAYOUT_INFLATER_SERVICE); // same as this method
LayoutInflater.from(context);
View view = mLayoutInflater.inlfate(R.layout.activity_main, null) //(int resource, ViewGroup root )
addContentView(view) // 可以將視圖放在很多地方
view.findViewById(R.id. 找到視圖裏面的任何一個控件)
--16min
提取佈局屬性 theme & style
Theme 針對窗體級別,改變窗體樣式 (for application, activity etc.
Style
//ctrl + o: enter class name
//ctrl + shift + o: enter file name
Style 可以繼承,也可以override
-- Course 2
build a new view
new a view class, exteneds view, new a constructor
View
- initialize a constructor
-onMeasure(); decides the size
-onLayout(); the location
-onDraw();
-invalidate(); to refresh
fast-key: ctrl+F12, search method in current class
3 ways to customize widget
1, extend an existing widget
2, extends from a layout file
3, extends from a view class
shift + F6: reconstruct
做一個簡單的自定義控件:15min
自定義視圖的屬性
-where
-what
-how to use those attributes
build a new .xml file under "values", <declare-styleable
xmlns: app="http://schemas.android.com/apk/res-auto"
自定義一個命名空間
Fragment
- fragment is a part of activity
- Create Fragment
. onCreate();
. onCreateView();
. onPause();
- Add Fragment
. Java Code
. Layout
- Replace Fragment
fragments can be used in one activity, or more
fragment has its own life period, is a modular activity, has its own behaviors, can be added, removed, deleted