ViewPager resize height to Content
- by user1324936
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);
}
});