ViewPager resize height to Content
Posted
by
user1324936
on Stack Overflow
See other posts from Stack Overflow
or by user1324936
Published on 2012-09-08T09:28:42Z
Indexed on
2012/09/08
9:38 UTC
Read the original article
Hit count: 232
ViewPager does not wrap its height to its content. For my layout I need to set the hight then dynamically because it is nested in other layouts. Therefore I created a ScrollView as content of the ViewPager and check its height in onCreate method of the Fragment, but the ScrollView has always the same size. How can I resize the ViewPager to fit to its content?
final ScrollView sv = (ScrollView) v.findViewById(R.id.sv);
ViewTreeObserver vto = scrollViewMenuFragen.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = sv.getMeasuredHeight();
//always same height independent of content height
//need to resize ViewPager
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) mPager.getLayoutParams();
params.height = height;
mPager.setLayoutParams(params);
}
});
© Stack Overflow or respective owner