java - ViewPager doesn't display the second and third views when height wrap_content -
i have viewpager
works views (not fragments). default viewpager has 1 view display sectionslayout
, , depending on webservice response might add 1 or 2 views viewpager. (promo1, promo2
)
the viewpager being small part of activity layout, height should height of first child : sectionslayout
, if needed add 1 or 2 other pages, (promo1, promo2
) should have same height sectionslayout
.
now, viewpager shows me correctly first embedded layout doesn't display second , third ones when height of viewpager set wrap_content
(it show them when height fixed on dps
, know it's common , known issue on viewpager, created custom viewpager based on answers here on takes height of first element.
flexibleviewpager.java :
public class flexibleviewpager extends viewpager { public flexibleviewpager (context context) { super (context); } public flexibleviewpager (context context, attributeset attrs) { super (context, attrs); } @override public void setoffscreenpagelimit(int limit) { super.setoffscreenpagelimit(limit); } @override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) { super.onmeasure (widthmeasurespec, heightmeasurespec); //view view = getchildat (this.getcurrentitem ()); view view = getchildat (0); if (view != null) { view.measure (widthmeasurespec, heightmeasurespec); } setmeasureddimension(getmeasuredwidth(), measureheight(heightmeasurespec, view)); } private int measureheight (int measurespec, view view) { int result = 0; int specmode = measurespec.getmode (measurespec); int specsize = measurespec.getsize(measurespec); if (specmode == measurespec.exactly) { result = specsize; } else { // set height base view if available if (view != null) { result = view.getmeasuredheight (); } if (specmode == measurespec.at_most) { result = math.min (result, specsize); } } return result; } }
layout :
... <com.widgets.flexibleviewpager android:id="@+id/corehomecontainer" android:layout_width="match_parent" android:layout_height="wrap_content"> <relativelayout android:id="@+id/sectionslayout" android:layout_width="match_parent" android:layout_height="wrap_content" /> <relativelayout android:id="@+id/promo1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/red" /> <relativelayout android:id="@+id/promo1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/green" /> </com.widgets.flexibleviewpager> ...
but second , third element not shown, though i'm able swipe, , pageradapter able create 3 pages needed, doesn't fill them promos1 , promos2
.
any idea ?
Comments
Post a Comment