标签:
package com.football.app.view;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
/**
* Created by Administrator on 2015/9/17.
*/
public class TestView extends Button {
public TestView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Log.d("测试代码", "TestView---TestView");
}
public TestView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Log.d("测试代码", "TestView---TestView");
}
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d("测试代码", "TestView---TestView");
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Log.d("测试代码", "TestView---onMeasure");
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
Log.d("测试代码", "TestView---onLayout");
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Log.d("测试代码", "TestView---onDraw");
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.d("测试代码", "TestView---onSizeChanged");
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Log.d("测试代码", "TestView---ACTION_UP----invalidate");
invalidate();
}
return super.onTouchEvent(event);
}
}
09-17 15:27:22.930 17644-17644/com.football.app D/测试代码﹕ TestView---TestView
09-17 15:27:22.992 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:22.993 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.031 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.032 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.037 17644-17644/com.football.app D/测试代码﹕ TestView---onSizeChanged
09-17 15:27:23.037 17644-17644/com.football.app D/测试代码﹕ TestView---onLayout
09-17 15:27:23.062 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.063 17644-17644/com.football.app D/测试代码﹕ TestView---onLayout
09-17 15:27:23.064 17644-17644/com.football.app D/测试代码﹕ TestView---onDraw
09-17 15:27:23.074 17644-17644/com.football.app D/测试代码﹕ TestView---onDraw
09-17 15:27:23.100 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.102 17644-17644/com.football.app D/测试代码﹕ TestView---onMeasure
09-17 15:27:23.108 17644-17644/com.football.app D/测试代码﹕ TestView---onLayout
09-17 15:27:23.111 17644-17644/com.football.app D/测试代码﹕ TestView---onDraw
根据上面的代码,调用顺序应该是 构造函数------->onMeasure------->onSizeChanged------->onLayout------->onDraw
后面有可能 onMeasure------->onLayout------->onDraw
标签:
原文地址:http://my.oschina.net/u/1175746/blog/507598