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);
            }
            
        }
    
    }
  • 相关阅读:
    Part 11 Search filter in AngularJS
    Part 10 AngularJS sort rows by table header
    Part 9 Sorting data in AngularJS
    Part 8 AngularJS filters
    Part 7Handling events in AngularJS
    Part 6 AngularJS ng repeat directive
    PHP单一入口应用程序概述
    SVN
    跨平台的.NET集成开发环境:MonoDevelop
    PHP中使用KindEditor
  • 原文地址:https://www.cnblogs.com/slowalker/p/3398982.html
Copyright © 2011-2022 走看看