Skip to content

Instantly share code, notes, and snippets.

@mrhether
Created May 27, 2015 17:52
Show Gist options
  • Save mrhether/c4990e6c8dbf75ba3c67 to your computer and use it in GitHub Desktop.
Save mrhether/c4990e6c8dbf75ba3c67 to your computer and use it in GitHub Desktop.
DynamicHeightViewPager
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment