http://blog.csdn.net/yoyo_newbie/article/details/47167933
The second step, hide the head file Headerview, this step is crucial for the novice.
The principle is to hide it by setting a negative number of the total height of his margintop. However, we call through direct
View. Getmeasuredheight ()
Direct access to a height of 0! So we need to solve this problem. We can measure the total height by notifying the parent layout, as follows
/*** Measure the true height of the view and return */ private intMeasureview(View view) {Linearlayout.layoutparams params = (layoutparams) view.getlayoutparams ();intwidth = linearlayout.Getchildmeasurespec(0, 0, Params.width);intTempheight = params.Height;intHeight = tempheight>0? Measurespec.Makemeasurespec(Tempheight, Measurespec.exactly): Measurespec.Makemeasurespec(0, Measurespec.UNSPECIFIED); View.measure (width, Height;returnView.getmeasuredheight ();}
Some of the knowledge I will not talk about, their own to check, won't be is unable to parse, more abstract, need to understand their own hands, do it for the year.
Then we define a height variable, hide the header file method and set the method of Headerview MarginTop
/** * Height of head file */ headerviewheight; /** * Hide Headerview * / privatehideheaderview() { //Set MarginTop to a negative total height can hide it directly setheaderviewmargintop (-headerviewheight );}
/*** Set header file Magrintop */private voidSetheaderviewmargintop(intTop) {Linearlayout.layoutparams params = (layoutparams)Heanderview. Getlayoutparams (); Params.setmargins (0,Top, 0, 0); Heanderview. Setlayoutparams (params);}
So we completed the method of hiding the Headerview.
The code after stitching. As follows
/*** with GIF drop -down * @authorSam */Public abstract classbasegifrefresh<VextendsView>extendslinearlayout{/*** Content Section */ PrivateVChilderview; /*** Implementation Content Section * @paramContext * @return */ protected AbstractVGetconvertview(Context context); PublicBasegifrefresh (Context Context, AttributeSet attrs) {Super(Context, ATTRS); Init (context); }/*** Refresh time, show the head */ PrivateViewHeanderview; /*** Initialize UI * @paramContext */ private voidInit(Context context) {//Set Vertical layout SetOrientation (LinearLayout.VERTICAL); //Add head Heanderview= Newheaderview (context); AddView (Heanderview); //Add Content section Childerview= Newchildview (context); AddView (Childerview); //Second step, height, hide Headerview//Get the height of the head///Direct access to the height of the view, the result is 0. So first measure the height of the head. Headerviewheight= Measureview (Heanderview); //Hide Headerview Hideheaderview (); }/*** Height of head file */ private intHeaderviewheight; /*** Hide Headerview */ private voidHideheaderview() {//Set the total height of the margintop to a negative number to hide it directly Setheaderviewmargintop (-Headerviewheight); }/*** Set header file Magrintop */ private voidSetheaderviewmargintop(intTop) {Linearlayout.layoutparams params = (layoutparams)Heanderview. Getlayoutparams (); Params.setmargins (0,Top, 0, 0); Heanderview. Setlayoutparams (params); }/*** Construct a head header * @paramContext * @return */ PrivateViewNewheaderview(Context context) {View Heanderview = Layoutinflater. from(context). Inflate (r.layout.Refresh_list_header, NULL); Linearlayout.layoutparams Headerviewparams =NewLinearlayout.layoutparams (Layoutparams.match_parent, Layoutparams.wrap_content); Heanderview.setlayoutparams (Headerviewparams);returnHeanderview; }/*** Component Content Section * @paramContext * @return */ PrivateVNewchildview(Context context) {Linearlayout.layoutparams Convertviewparams =NewLinearlayout.layoutparams (Layoutparams.match_parent, Layoutparams.match_parent); Convertviewparams.Weight=1; VChildview = Getconvertview (context); Childview.setbackgroundcolor (Color.RED);//TODO to see the effect, test it. Childview.setlayoutparams (Convertviewparams);returnChildview; }/*** Measure the true height of the view and return */private intMeasureview(View view) {Linearlayout.layoutparams params = (layoutparams) view.getlayoutparams ();intwidth = linearlayout.Getchildmeasurespec(0, 0, Params.width);intTempheight = params.Height;intHeight = tempheight>0? Measurespec.Makemeasurespec(Tempheight, Measurespec.exactly): Measurespec.Makemeasurespec(0, Measurespec.UNSPECIFIED); View.measure (width, Height;returnView.getmeasuredheight ();}}
:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Step-by-step implementation of GIF animation drop-down (ii)