Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved the problem with a couple of hacks. Here is what it involves:</p> <p>First, I needed a layout that would ignore <code>ViewPager</code>'s height limit. Used it as a parent layout for <code>ViewPager</code> items.</p> <pre><code>public class TallLinearLayout extends LinearLayout { public TallLinearLayout(Context context) { super(context); } public TallLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } public TallLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, MeasureSpec.UNSPECIFIED); } } </code></pre> <p>I then wrote the logic for resizing ViewPager:</p> <pre><code>private class ViewPagerContentWrapper implements OnGlobalLayoutListener { private ViewPager mViewPager; public ViewPagerContentWrapper(ViewPager viewPager) { mViewPager = viewPager; } @Override public void onGlobalLayout() { int position = mViewPager.getCurrentItem(); check(position); check(position + 1); } private void check(int position) { ViewGroup vg = (ViewGroup) mViewPager.getChildAt(position); View v = vg == null ? null : vg.getChildAt(0); if (v != null) { int height = v.getHeight(); if (height &gt; mViewPager.getHeight()) { resize(height); } } } private void resize(int height) { mViewPager.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, height ) ); } } </code></pre> <p>Which I registered as global layout listener:</p> <pre><code>viewPager.getViewTreeObserver().addOnGlobalLayoutListener(new ViewPagerContentWrapper(viewPager)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload