Note that there are some explanatory texts on larger screens.

plurals
  1. POViewPager not supporting layout_height = wrap_content
    text
    copied!<p>I'm building an android application with the following layout.<img src="https://i.stack.imgur.com/x1LVx.png" alt="application layout"></p> <p>It's already known that <code>layout_height="wrap_content"</code> doesn't work for the ViewPager. </p> <p>My question is how to change it dynamically. The content of the ViewPager is inflated from two xml layouts, <code>vp_statistics.xml and vp_campaigns.xml.</code></p> <p>here's the xml for the ViewPager</p> <pre><code>&lt;LinearLayout android:id="@+id/topcontent_wrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/viewpager_wrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="vertical" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here's the code for my PagerAdapter</p> <pre><code>class MyPagerAdapter extends PagerAdapter{ @Override public int getCount() { // TODO Auto-generated method stub return 2; } public Object instantiateItem(View collection, int pos){ LayoutInflater inflater = (LayoutInflater)collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resId = 0; switch(pos){ case 0: resId = R.layout.vp_statistics; break; case 1: resId = R.layout.vp_campaigns; break; } View view = inflater.inflate(resId, null); ((ViewPager)collection).addView(view, 0); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { // TODO Auto-generated method stub ((ViewPager)container).removeView((View)object); } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0 == ((View)arg1); } @Override public Parcelable saveState() { // TODO Auto-generated method stub return null; } } </code></pre> <p>and inside my onCreate() mthod of the Activity class:</p> <pre><code>MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager viewPager = (ViewPager)findViewById(R.id.viewpager); viewPager.setAdapter(adapter); viewPager.setCurrentItem(0); </code></pre> <p>Is there a way to get the height of the <code>vp_statistics.xml</code> and <code>vp_campaigns.xml</code> layouts and assign it dynamically to <code>ViewPager (@id/viewpager)</code> every time the <code>instantiateItem()</code> object gets called?</p>
 

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