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


[size=l代码如下:[/size] 
Java代码   收藏代码
  1. public class TestView extends View {  
  2.   
  3.     public TestView(Context context) {  
  4.         super(context);  
  5.         Log.d("mDebug""TestView context");  
  6.     }  
  7.   
  8.       
  9.       
  10.     public TestView(Context context, AttributeSet attrs, int defStyle) {  
  11.         super(context, attrs, defStyle);  
  12.         Log.d("mDebug""TestView context,attrs,defStyle attrs="+attrs.getAttributeValue(0));  
  13.     }  
  14.   
  15.   
  16.   
  17.     public TestView(Context context, AttributeSet attrs) {  
  18.         super(context, attrs);  
  19.         Log.d("mDebug""TestView context, attrs="+attrs.getAttributeValue(0));  
  20.     }  
  21.   
  22.   
  23.   
  24.     @Override  
  25.     protected void onDraw(Canvas canvas) {  
  26.         // TODO Auto-generated method stub  
  27.         super.onDraw(canvas);  
  28.         Log.d("mDebug""onDraw");  
  29.     }  
  30.   
  31.     @Override  
  32.     protected void onFinishInflate() {  
  33.         // TODO Auto-generated method stub  
  34.         super.onFinishInflate();  
  35.         Log.d("mDebug""onFinishInflate");  
  36.     }  
  37.   
  38.   
  39.   
  40.     @Override  
  41.     protected void onSizeChanged(int w, int h, int oldw, int oldh) {  
  42.         // TODO Auto-generated method stub  
  43.         super.onSizeChanged(w, h, oldw, oldh);  
  44.         Log.d("mDebug""onSizeChanged,w="+w+",h="+h+",oldw="+oldw+",oldh="+oldh);  
  45.     }  
  46.   
  47. }  

结果如下: 
Java代码   收藏代码
  1. 12-05 22:23:03.587: D/mDebug(9715): TestView context, attrs=@2131034112  
  2. 12-05 22:23:03.597: D/mDebug(9715): onFinishInflate  
  3. 12-05 22:23:03.667: D/mDebug(9715): onSizeChanged,w=240,h=282,oldw=0,oldh=0  
  4. 12-05 22:23:03.727: D/mDebug(9715): onDraw  
  5. 12-05 22:23:03.757: D/mDebug(9715): onDraw  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值