android - onMeasure(...) being passed MeasureSpec.EXACTLY, apparently wrongly -


i've created custom view implements onmeasure:

@override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     float width = measurespec.getsize(widthmeasurespec);     final int widthmode = measurespec.getmode(widthmeasurespec);      float height = measurespec.getsize(heightmeasurespec);     final int heightmode = measurespec.getmode(heightmeasurespec);      float nominalheight = getresources().getinteger(r.integer.nominalheight);     float nominalwidth = getresources().getinteger(r.integer.nominalwidth);      float aspectratio = nominalwidth / nominalheight;      if( width / height > aspectratio //too wide             && (                     widthmode == measurespec.at_most ||                     widthmode == measurespec.unspecified              )             ) {          width -= (width - height * aspectratio);     }     if( width / height < aspectratio //too tall             && (                     heightmode == measurespec.at_most ||                     heightmode == measurespec.unspecified              )             ) {          height -= (height - width / aspectratio);     }      setmeasureddimension((int)width, (int)height); } 

the intention is, possible, create rectangle aspect ratio same 1 specified nominalheight , nominalwidth. if function passed measurespec.exactly should lay out dimension given in direction.

i'm laying view out wrap_content in xml in both directions. what's puzzling me that, stepping through onmeasure calls, half of them show measurespec.at_most , routine calculates correct rectangle, , other half show measurespec.exactly , uses given dimensions. more puzzlingly, if disable conditionality (i assume, documentation , example code, incorrectly) works fine.

why getting these alternating calls different values, , how can persuade android lay view out in correct dimensions?


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -