This extend class for viewpager where wrap your content of viewpager according to size of your view content
Last active
April 8, 2018 15:04
-
-
Save afiqiqmal/33972c28d9999bdc75b15e597ef47d26 to your computer and use it in GitHub Desktop.
This Viewpager wrap your content according to size of your view content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WrapContentViewPager extends ViewPager { | |
public WrapContentViewPager(Context context) | |
{ | |
super(context); | |
} | |
public WrapContentViewPager(Context context, AttributeSet attrs) | |
{ | |
super(context, attrs); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
super.onMeasure(widthMeasureSpec, 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