From: http://blog.csdn.net/you_and_me12/article/details/7327030
Slidingdrawer is not described if it is used in many ways.
If the property layout_height = "wrap_content" is set, the onmeasure () method in the original slidingdrawer makes layout_height always fill_parent, but layout_height = "fixed height" is also acceptable!
Rewrite slidingdrawer as follows (right image ):
Code:
/*** Make slidingdrawer at the low end of the screen, instead of filling the whole screen * @ author Akai 2012-03-06 */public class wrapslidingdrawer extends slidingdrawer {private Boolean mvertical; private int mtopoffset; public wrapslidingdrawer (context, attributeset attrs, int defstyle) {super (context, attrs, defstyle); int orientation = attrs. getattributeintvalue ("android", "orientation", orientation_vertical); mtopoffset = attrs. getattributeintvalue ("android", "topoffset", 0); mvertical = (orientation = slidingdrawer. orientation_vertical);} public wrapsconfiguringdrawer (context, attributeset attrs) {super (context, attrs); int orientation = attrs. getattributeintvalue ("android", "orientation", orientation_vertical); mtopoffset = attrs. getattributeintvalue ("android", "topoffset", 0); mvertical = (orientation = slidingdrawer. orientation_vertical);} @ override protected void onmeasure (INT widthmeasurespec, int heightmeasurespec) {int widthspecmode = measurespec. getmode (widthmeasurespec); int widthspecsize = measurespec. getsize (widthmeasurespec); int heightspecmode = measurespec. getmode (heightmeasurespec); int heightspecsize = measurespec. getsize (heightmeasurespec); final view handle = gethandle (); final view content = getcontent (); measurechild (handle, widthmeasurespec, heightmeasurespec); If (mvertical) {int Height = heightspecsize-handle. getmeasuredheight ()-mtopoffset; content. measure (widthmeasurespec, measurespec. makemeasurespec (height, heightspecmode); heightspecsize = handle. getmeasuredheight () + mtopoffset + content. getmeasuredheight (); widthspecsize = content. getmeasuredwidth (); If (handle. getmeasuredwidth ()> widthspecsize) widthspecsize = handle. getmeasuredwidth ();} else {int width = widthspecsize-handle. getmeasuredwidth ()-mtopoffset; getcontent (). measure (measurespec. makemeasurespec (width, widthspecmode), heightmeasurespec); widthspecsize = handle. getmeasuredwidth () + mtopoffset + content. getmeasuredwidth (); heightspecsize = content. getmeasuredheight (); If (handle. getmeasuredheight ()> heightspecsize) heightspecsize = handle. getmeasuredheight ();} setmeasureddimension (widthspecsize, heightspecsize );}}
Note: This code can be used directly without modification. You only need to change the original <slidingdrawer> label to <packagename. wrapslidingdrawer>.