zoukankan      html  css  js  c++  java
  • Android:View

    View

    View's Main Draw Process:

    1. onMeasure()                          Called to determine the size requirements for this view and all its children.
    2. onLayout()                             Called when this view should assign a size and postion to all of its children.       
    3. onDraw()                               Called when this view render its content.          
    4. dispatchDraw()                      Called by draw to draw its child view.

    The following source code for a test:

    package com.slowalker.viewdemo;
    
    import android.os.Bundle;
    import android.os.Parcelable;
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.LinearLayout;
    
    public class MainActivity extends Activity {
    
        private static final String TAG = MainActivity.class.getSimpleName();
        
        private static final boolean DEBUG = true;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (DEBUG) {
                Log.d(TAG, "onCreate");
            }
            setContentView(new SView(this), new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            
        }
        
        private static class SView extends View {
    
            private static final String TAG = SView.class.getSimpleName();
            
            public SView(Context context) {
                super(context);
            }
    
            @Override
            protected void dispatchDraw(Canvas canvas) {
                if (DEBUG) {
                    Log.d(TAG, "dispatchDraw");
                }
                super.dispatchDraw(canvas);
                
            }
    
            @Override
            protected void onDraw(Canvas canvas) {
                if (DEBUG) {
                    Log.d(TAG, "onDraw");
                }
                super.onDraw(canvas);
            }
    
            @Override
            protected void onLayout(boolean changed, int left, int top, int right,
                    int bottom) {
                if (DEBUG) {
                    Log.d(TAG, "onLayout");
                }
                super.onLayout(changed, left, top, right, bottom);
            }
    
            @Override
            protected void onFinishInflate() {
                if (DEBUG) {
                    Log.d(TAG, "onFinishInflate");
                }
                super.onFinishInflate();
            }
    
            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                if (DEBUG) {
                    Log.d(TAG, "onMeasure");
                }
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
            
        }
    
    }
  • 相关阅读:
    2016年3月至9月随笔
    带大三个hybird app项目的设计管理笔记
    小议新人的培养
    GitHub上整理的一些工具,求补充——转的,先mark了
    AutoMapper(一)——实现数据契约和实体类之间的转换
    GitHub上整理的一些工具
    我最常用的7个Web在线工具
    在线团队协作工具+在线UML工具
    轻量级SaaS在线作图工具(继之前介绍后完整介绍)
    分享自己使用的在线UML画图工具
  • 原文地址:https://www.cnblogs.com/slowalker/p/3398982.html
Copyright © 2011-2022 走看看