Android drawer slidingdrawer -- wrap_content non-full screen

Source: Internet
Author: User

Address: 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 ):

-->

Post 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>.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.