title: How to change height of ViewPager according to current tab?
body: <p>I created a <code>DialogFragment</code> and there is a <code>ViewPager</code> inside it, which has 3 tabs. I want to change <code>ViewPager</code>'s height according to current tab. Here is my code:</p>
  
  <pre><code>mViewPager.setAdapter(mAdapter);
  mTabLayout.setupWithViewPager(mViewPager); //TabLayout of Android Support Design Library
  mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
      @Override
      public void onPageSelected(int position) {
          super.onPageSelected(position);
          ViewGroup.LayoutParams params = mViewPager.getLayoutParams();
          params.height = mTabHeights.get(position);
      }
  });
  </code></pre>
  
  <p>This isn't always useful. When I scroll the <code>ViewPager</code>, it can change the height dynamically according to current tab, everything works well. However, <strong>when I click tabs inside <code>TabLayout</code></strong>, the page can't always change into tab I want to select. Besides, I can see some strange behaviors like:</p>
  
  <ol>
  <li>The indicator scrolled to correct position, but textColors of both previous tab and tab I want to select don't change(I've set different colors for selected and unselected tabs by <code>TabLayout</code>'s API)</li>
  <li>The indicator scrolled to correct position, colors are also right. <code>ViewPager</code>'s height is changed into correct number too, but tab's content is wrong(Sometimes it doesn't change, sometimes it becomes blank). </li>
  </ol>
  
  <p>I found that onPageSelected() wasn't always called when I clicked tabs inside <code>TabLayout</code>. But if I move the code of changing <code>LayoutParams</code> of <code>ViewPager</code>, it can be called correctly.</p>
  
  <p>So, what's the problem? <strong>And How can I change ViewPager's height dynamically for different tabs?</strong> Thanks for any answers/comments in advance!</p>