This article transferred from: http://blog.csdn.net/u012604322/article/details/17097105
The above two views are not given in the Android API but a widget view that is used in call answering and alarm clock--glowpadview.java
We use the source code to see how the size of this view is controlled by Onmeasure.
@Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { Final intMinimumwidth =getsuggestedminimumwidth (); Final intMinimumheight =getsuggestedminimumheight (); intComputedwidth =resolvemeasured (Widthmeasurespec, minimumwidth); intComputedheight =resolvemeasured (Heightmeasurespec, minimumheight); Setmeasureddimension (Computedwidth, computedHeight); }
@Override protectedint getsuggestedminimumwidth () { // View should is large enough to contain the background + handle and // target drawable on either edge. return (int) (Math.max (Mouterring.getwidth (), 2 * Mouterradius) + mmaxtargetwidth); }
The mouterring is a specified circle (drawn by shape, so the width and height, equivalent to the radius of the circle), Mouterradius the radius of the largest dashed circle, and mmaxtargetwidth as the widths of the zzz picture or other image in the figure. This part of the value is the size of the properties that have been specified by the developer themselves in their own view
Private intResolvemeasured (intMeasurespec,intdesired) { intresult = 0; intSpecsize =measurespec.getsize (MEASURESPEC); Switch(Measurespec.getmode (Measurespec)) { CaseMeasureSpec.UNSPECIFIED:result=desired; Break; CaseMeasureSpec.AT_MOST:result=math.min (specsize, desired); Break; Casemeasurespec.exactly:default: Result=specsize; } returnresult; }
From the width analysis, the viewgroup that hosts this view may have two situations, one (a) providing more space than the value we give above, and two (B) being small (we will not allow this to happen in development, but the logic of design still has to take this into account). Then it is to see the view of the Layout_width, one is wrap_content, corresponding to At_most,a to get the value of the given value, b value is the value of the parent view, although we do not want this, but the parent view only gives the space, we have to do so.
The second is the match_parent, which corresponds to the value of only one parent view, which is also in line with the requirements.
A good design should take into account the use of a variety of situations, and a reusable framework design is more so, before the design needs to anticipate a variety of possible applications.
onmeasure Example Analysis