Android ViewPager with dynamic height -


i have viewpager show fragments , swipe between them height of viewpager dynamic based on content. assume have multiple list each list placed in 1 tab , changing tabs height of viewpager should change created custom viewpager , overrided onmeasure problem viewpager creates next fragment sooner current fragment (visible one) gets it's height next fragment measure.

here myviewpager : public class myviewpager extends viewpager {

public myviewpager(context context) {         super(context);     }      public myviewpager(context context, attributeset attrs) {         super(context, attrs);     }       @override     protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         int height = 0;         for(int = 0; < getchildcount(); i++) {             view child = getchildat(i);             child.measure(widthmeasurespec, measurespec.makemeasurespec(0, measurespec.unspecified));             int h = child.getmeasuredheight();             if(h > height) height = h;         }          heightmeasurespec = measurespec.makemeasurespec(height, measurespec.exactly);          super.onmeasure(widthmeasurespec, heightmeasurespec);     }  } 

i tried trigger onmeasure method of myviewpager when fragment become visible below nothing changes.

@override public void setuservisiblehint(boolean isvisibletouser) {     super.setuservisiblehint(isvisibletouser);         if (isvisibletouser) {             postdetailsactivity activity = (postdetailsactivity) getactivity();             activity.pagerparent.requestlayout();             activity.pagerparent.invalidate();     }  } 

i found solution here if else wondering how make viewpager change it's height dynamically.

also can find quick answer here if don't have time @ git.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -