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);
            }
            
        }
    
    }
  • 相关阅读:
    区块链技术驱动金融.mobi
    ProcessExplorer 工具下载
    免费的论文查重网站
    接口可以继承接口吗?
    比较中的自动拆装箱
    Java语言中的异常处理
    Java类加载过程
    通过反射访问父类的私有成员
    final关键字详解
    MVC 控制台 +log4net 存入数据库
  • 原文地址:https://www.cnblogs.com/slowalker/p/3398982.html
Copyright © 2011-2022 走看看