zoukankan      html  css  js  c++  java
  • 在进程View时的四个构造函数详解

    public View(Context context):
    源代码中的解释如下:在Code中实例化一个View就会调用第一个构造函数
       /**
         * Simple constructor to use when creating a view from code.
         *
         * @param context The Context the view is running in, through which it can
         *        access the current theme, resources, etc.
         */
    
    
    public View(Context context, @Nullable AttributeSet attrs):
    源代码解释如下:在xml中定义会调用第二个构造函数
        /**
         * Constructor that is called when inflating a view from XML. This is called
         * when a view is being constructed from an XML file, supplying attributes
         * that were specified in the XML file. This version uses a default style of
         * 0, so the only attribute values applied are those in the Context's Theme
         * and the given AttributeSet.
         *
         * <p>
         * The method onFinishInflate() will be called after all children have been
         * added.
         *
         * @param context The Context the view is running in, through which it can
         *        access the current theme, resources, etc.
         * @param attrs The attributes of the XML tag that is inflating the view.
         * @see #View(Context, AttributeSet, int)
         */
    public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr):
    源代码解释如下:允许继承View的子类使用他们自己的基本样式来生成View
    
    
        /**
         * Perform inflation from XML and apply a class-specific base style from a
         * theme attribute. This constructor of View allows subclasses to use their
         * own base style when they are inflating. For example, a Button class's
         * constructor would call this version of the super class constructor and
         * supply <code>R.attr.buttonStyle</code> for <var>defStyleAttr</var>; this
         * allows the theme's button style to modify all of the base view attributes
         * (in particular its background) as well as the Button class's attributes.
         *
         * @param context The Context the view is running in, through which it can
         *        access the current theme, resources, etc.
         * @param attrs The attributes of the XML tag that is inflating the view.
         * @param defStyleAttr An attribute in the current theme that contains a
         *        reference to a style resource that supplies default values for
         *        the view. Can be 0 to not look for defaults.
         * @see #View(Context, AttributeSet)
         */
    
    
    
    public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes):
    源代码解释如下:
      /**
         * Perform inflation from XML and apply a class-specific base style from a
         * theme attribute or style resource. This constructor of View allows
         * subclasses to use their own base style when they are inflating.
         * <p>
         * When determining the final value of a particular attribute, there are
         * four inputs that come into play:
         * <ol>
         * <li>Any attribute values in the given AttributeSet.
         * <li>The style resource specified in the AttributeSet (named "style").
         * <li>The default style specified by <var>defStyleAttr</var>.
         * <li>The default style specified by <var>defStyleRes</var>.
         * <li>The base values in this theme.
         * </ol>
         * <p>
         * Each of these inputs is considered in-order, with the first listed taking
         * precedence over the following ones. In other words, if in the
         * AttributeSet you have supplied <code>&lt;Button * textColor="#ff000000"&gt;</code>
         * , then the button's text will <em>always</em> be black, regardless of
         * what is specified in any of the styles.
         *
         * @param context The Context the view is running in, through which it can
         *        access the current theme, resources, etc.
         * @param attrs The attributes of the XML tag that is inflating the view.
         * @param defStyleAttr An attribute in the current theme that contains a
         *        reference to a style resource that supplies default values for
         *        the view. Can be 0 to not look for defaults.
         * @param defStyleRes A resource identifier of a style resource that
         *        supplies default values for the view, used only if
         *        defStyleAttr is 0 or can not be found in the theme. Can be 0
         *        to not look for defaults.
         * @see #View(Context, AttributeSet, int)
         */
     
     
     
  • 相关阅读:
    CF821E 【Okabe and El Psy Kongroo】
    BZOJ1231: [Usaco2008 Nov]mixup2 混乱的奶牛
    P1896 [SCOI2005]互不侵犯
    QBXT Day 2 记录
    CF467C George and Job
    【luogu P3373 线段树2】 模板
    【luogu P1306 斐波那契公约数】 题解
    【luogu T24743 [愚人节题目5]永世隔绝的理想乡】 题解
    【luogu P1903 [国家集训队]数颜色】 题解
    莫队算法~讲解
  • 原文地址:https://www.cnblogs.com/liaojie970/p/5846435.html
Copyright © 2011-2022 走看看