I am trying to put a ViewPager
with different fragments with different heights. I know that wrap_content
is not working with ViewPager
so I am trying to set pager height dinamically.
I am setting the pager height in a page listener:
...
indicator.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int selected) {
final View view = fragments[selected].getView();
if (view != null) {
pager.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, view
.getMeasuredHeight()));
}
}
Unfortunately it is not working because the value returned by getMeasuredHeight()
on Fragment
is wrong. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…