android,view的执行过程onDraw、onSizeChanged,onFinishInflate

Android  /  houtizong 发布于 3年前   99
小试view的执行过程,此是入门,高手绕道。

--------------------------------------------------------------------------------
此为抛砖引玉,个人看官自己发挥。
结果如下:


12-05 22:23:03.587: D/mDebug(9715): TestView context, attrs=@213103411212-05 22:23:03.597: D/mDebug(9715): onFinishInflate12-05 22:23:03.667: D/mDebug(9715): onSizeChanged,w=240,h=282,oldw=0,oldh=012-05 22:23:03.727: D/mDebug(9715): onDraw12-05 22:23:03.757: D/mDebug(9715): onDraw

[size=l代码如下:[/size]
public class TestView extends View {public TestView(Context context) {super(context);Log.d("mDebug", "TestView context");}public TestView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);Log.d("mDebug", "TestView context,attrs,defStyle attrs="+attrs.getAttributeValue(0));}public TestView(Context context, AttributeSet attrs) {super(context, attrs);Log.d("mDebug", "TestView context, attrs="+attrs.getAttributeValue(0));}@Overrideprotected void onDraw(Canvas canvas) {// TODO Auto-generated method stubsuper.onDraw(canvas);Log.d("mDebug", "onDraw");}@Overrideprotected void onFinishInflate() {// TODO Auto-generated method stubsuper.onFinishInflate();Log.d("mDebug", "onFinishInflate");}@Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {// TODO Auto-generated method stubsuper.onSizeChanged(w, h, oldw, oldh);Log.d("mDebug", "onSizeChanged,w="+w+",h="+h+",oldw="+oldw+",oldh="+oldh);}}


问题: 构造函数的context为何物,attrs从何处来

看到这篇文章貌似解决了以上问题。
http://blog.csdn.net/z103594643/article/details/6755017

扩展地址:http://developer.android.com/reference/android/view/View.html

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客