android - BottomSheet with ViewPager and Fragments? -
i want view in older version of streetview.
i have tried bottomsheetbehavior viewpager, dynamic height of fragments not working properly.
using customviewpager can set height of fragment
public class custompager extends viewpager { private view mcurrentview; public custompager(context context) { super(context); } public custompager(context context, attributeset attrs) { super(context, attrs); } @override public void onmeasure(int widthmeasurespec, int heightmeasurespec) { if (mcurrentview == null) { super.onmeasure(widthmeasurespec, heightmeasurespec); return; } int height = 0; mcurrentview.measure(widthmeasurespec, measurespec.makemeasurespec(0, measurespec.unspecified)); int h = mcurrentview.getmeasuredheight(); if (h > height) height = h; heightmeasurespec = measurespec.makemeasurespec(height, measurespec.exactly); super.onmeasure(widthmeasurespec, heightmeasurespec); } public void measurecurrentview(view currentview) { mcurrentview = currentview; requestlayout(); } public int measurefragment(view view) { if (view == null) return 0; view.measure(0, 0); return view.getmeasuredheight(); }}
and add in adapter add these lines too
private int mcurrentposition = -1; @override public void setprimaryitem(viewgroup container, int position, object object) { super.setprimaryitem(container, position, object); if (position != mcurrentposition) { fragment fragment = (fragment) object; custompager pager = (custompager) container; if (fragment != null && fragment.getview() != null) { mcurrentposition = position; pager.measurecurrentview(fragment.getview()); } } }