android - Correctly implementing onMeasure() when extending a ViewGroup -


one of android samples (fixedgridlayout) extends viewgroup allow custom transitions when new items added grid. code works expected, doesn't implement scrolling. wrapped entire layout in scrollview expecting solve issue. however, appears fixedgridlayout view larger should be, leaving lot of scrollable space after items.

i suspect issue related way onmeasure() implemented. right, , if so, wrong code?

@override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     int cellwidthspec = measurespec.makemeasurespec(mcellwidth, measurespec.at_most);     int cellheightspec = measurespec.makemeasurespec(mcellheight, measurespec.at_most);      int count = getchildcount();     (int index=0; index<count; index++) {         final view child = getchildat(index);         child.measure(cellwidthspec, cellheightspec);     }      // use size our parents gave us, default minimum size avoid     // clipping transitioning children     int mincount =  count > 3 ? count : 3;     setmeasureddimension(resolvesize(mcellwidth * mincount, widthmeasurespec),             resolvesize(mcellheight * mincount, heightmeasurespec)); } 

scrollview cares vertical height of inner child view after measuring it, not scroll unless inner child sets height larger parent.

you call getheight() on inner view see if it's computed larger value expected. method valid after layout complete.

the code posted appear have mistake in it.

int mincount =  count > 3 ? count : 3; setmeasureddimension(resolvesize(mcellwidth * mincount, widthmeasurespec),         resolvesize(mcellheight * mincount, heightmeasurespec)); 

the code setting width , height based upon total number of children. if assume grid layout pattern, width calculated mcellwidth * columns , height calculated mcellheight * rows.

if set height value using total number of children, explain why scrolling beyond bottom of layout.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -