zoukankan      html  css  js  c++  java
  • android view 中各函数的执行顺数

    这个就好像是 activity 的生命周期一样,如果我们要使用自定义的 view,那么就很有必要了解一下 view 的那些能够被重写的函数的执行顺序。废话不多讲,以常用的5个函数为例子,见下文:

     1 package com.example.pulltorefreshtest;
     2 
     3 import android.content.Context;
     4 import android.graphics.Canvas;
     5 import android.util.AttributeSet;
     6 import android.util.Log;
     7 import android.view.View;
     8 
     9 /**
    10  * Created by Administrator on 2015/7/12.
    11  */
    12 public class testView extends View {
    13     public testView(Context context, AttributeSet attrs) {
    14         super(context, attrs);
    15     }
    16 
    17     @Override
    18     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    19         Log.d("------","---onMeasure");
    20         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    21     }
    22 
    23     @Override
    24     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    25         Log.d("------","---onLayout");
    26         super.onLayout(changed, left, top, right, bottom);
    27     }
    28 
    29     @Override
    30     protected void onFinishInflate() {
    31         Log.d("------","---onFinanshInflate");
    32         super.onFinishInflate();
    33     }
    34 
    35     @Override
    36     protected void onDraw(Canvas canvas) {
    37         Log.d("------","---onDraw");
    38         super.onDraw(canvas);
    39     }
    40 
    41     @Override
    42     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    43         Log.d("------","---onSizeChanged");
    44         super.onSizeChanged(w, h, oldw, oldh);
    45     }
    46 }

    运行结果:

    07-12 13:44:45.413  23734-23734/? D/------﹕ ---onFinanshInflate
    07-12 13:44:45.443  23734-23734/? D/------﹕ ---onMeasure
    07-12 13:44:45.493  23734-23734/? D/------﹕ ---onSizeChanged
    07-12 13:44:45.493  23734-23734/? D/------﹕ ---onLayout
    07-12 13:44:45.503  23734-23734/? D/------﹕ ---onMeasure
    07-12 13:44:45.503  23734-23734/? D/------﹕ ---onLayout
    07-12 13:44:45.503  23734-23734/? D/------﹕ ---onDraw
    

      

  • 相关阅读:
    在UpdatePanel上使用FileUpload上传文件
    Android配置开发环境
    文件服务器共享目录设置(一)
    win2008R2的Hyperv安装Ubuntu
    Comodo Time Machine导致系统进不去
    sql2005生成sql2000脚本的时候出现“User.UserType: NoLogin 不是SQL Server 2005 的有效选项“ 的解决方案
    迅雷7偷偷上传文件导致机器变卡
    文件服务器共享目录设置(二)
    再谈Javascript原型继承
    a和a:link的区别
  • 原文地址:https://www.cnblogs.com/linguanh/p/4640884.html
Copyright © 2011-2022 走看看