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);
            }
            
        }
    
    }
  • 相关阅读:
    金蝶,用友,浪潮erp介绍
    Javascript(Prototype)继承机制的设计思想
    IEnumerator和IEnumerable的关系
    MVC实用构架实战(一)——使用MEF实现IOC
    sql 数字转换为字符串补0
    scrum角色及其职责介绍
    NPOI 名称空间介绍
    双循环排序与冒泡排序的区别
    Silverlight 应用 WCF RIA Services 在 IIS6 部署问题总结
    PD15 数据库反向工程
  • 原文地址:https://www.cnblogs.com/slowalker/p/3398982.html
Copyright © 2011-2022 走看看