This is like the life cycle of the activity, and if we are going to use a custom view, then it is necessary to understand the order of execution of the functions that can be overridden by the view . Don't say much nonsense, take the usual 5 functions as an example, see below:
1 Packagecom.example.pulltorefreshtest;2 3 ImportAndroid.content.Context;4 ImportAndroid.graphics.Canvas;5 ImportAndroid.util.AttributeSet;6 ImportAndroid.util.Log;7 ImportAndroid.view.View;8 9 /**Ten * Created by Administrator on 2015/7/12. One */ A Public classTestViewextendsView { - PublicTestView (Context context, AttributeSet attrs) { - Super(context, attrs); the } - - @Override - protected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { +LOG.D ("------", "---onmeasure"); - Super. Onmeasure (Widthmeasurespec, heightmeasurespec); + } A at @Override - protected voidOnLayout (BooleanChangedintLeftintTopintRightintbottom) { -LOG.D ("------", "---onlayout"); - Super. OnLayout (changed, left, top, right, bottom); - } - in @Override - protected voidonfinishinflate () { toLOG.D ("------", "---onfinanshinflate"); + Super. Onfinishinflate (); - } the * @Override $ protected voidOnDraw (canvas canvas) {Panax NotoginsengLOG.D ("------", "---onDraw"); - Super. OnDraw (canvas); the } + A @Override the protected voidOnsizechanged (intWintHintOLDW,intOLDH) { +LOG.D ("------", "---onsizechanged"); - Super. Onsizechanged (W, H, OLDW, OLDH); $ } $}
Operation Result:
07-12 13:44:45.413 23734-23734/? d/------:---onfinanshinflate07-12 13:44:45.443 23734-23734/? d/------:---onmeasure07-12 13:44:45.493 23734-23734/? d/------:---onsizechanged07-12 13:44:45.493 23734-23734/? d/------:---onlayout07-12 13:44:45.503 23734-23734/? d/------:---onmeasure07-12 13:44:45.503 23734-23734/? d/------:---onlayout07-12 13:44:45.503 23734-23734/? d/------:---OnDraw
The number of execution smoothing for each function in Android view