您的位置:首页 > 移动开发 > Android开发

Android 应用界面开发笔记 自定义控件与Handler -待更新

2016-03-20 22:58 471 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: