How to set dynamic height to view pager child fragments in android? -


i having view pager 4 different fragments. in this, 3 fragments contains webview. fragments load different contents. unable set height based on loaded content. that, wrote custom viewpager measure height of viewpager. first viewpager fragment, height calculated properly. when navigate second or third fragment, viewpager height not calculated accurately. don't know, issue in code , need change calculate proper height each fragment after navigate view pager page. here view pager , pager adapter codes. kindly me.

custom view pager:

public class customviewpager extends viewpager {  public customviewpager (context context) {     super(context); }  public customviewpager (context context, attributeset attrs) {     super(context, attrs); }  @override public void onmeasure(int widthmeasurespec, int heightmeasurespec) {     super.onmeasure(widthmeasurespec, heightmeasurespec);      boolean wrapheight = measurespec.getmode(heightmeasurespec) == measurespec.at_most;      final view tab = getchildat(0);     int width = getmeasuredwidth();     int tabheight = tab.getmeasuredheight();      if (wrapheight) {         // keep current measured width.         widthmeasurespec = measurespec.makemeasurespec(width, measurespec.exactly);     }      int fragmentheight = measurefragment(((fragment) getadapter().instantiateitem(this, getcurrentitem())).getview());     heightmeasurespec = measurespec.makemeasurespec(tabheight + fragmentheight + (int) typedvalue.applydimension(typedvalue.complex_unit_dip, 50, getresources().getdisplaymetrics()), measurespec.at_most);      super.onmeasure(widthmeasurespec, heightmeasurespec); }  @override public void setonpagechangelistener(onpagechangelistener listener) {     requestlayout();     invalidate();     super.setonpagechangelistener(listener); }  @override public void addonpagechangelistener(onpagechangelistener listener) {     super.addonpagechangelistener(listener);  }  public int measurefragment(view view) {     if (view == null)         return 0;      view.measure(0, 0);     return view.getmeasuredheight(); }  } 

pageradapter:

public class merchantscataadapter extends fragmentpageradapter { context context; merchant merchant; fragment fragment;  private int mcurrentposition = -1;  private string[] tabs = {"home", "about us","promotions","store information"};  public merchantscataadapter(fragmentmanager fm, context context,merchant merchant) {     super(fm);     this.context = context;     this.merchant = merchant;  }  @override public fragment getitem(int index) {      switch (index) {         case 0:             fragment= new homecontentfragment().newinstance(merchant.getcompany_home_content(),merchant.getvideo_url());             break;         case 1:             fragment= new aboutusfragment().newinstance(merchant.getfull_description(),merchant.getvideo_url());             break;         case 2:             fragment= new aboutusfragment().newinstance(merchant.getcompany_promotions(),merchant.getvideo_url());             break;         case 3:             fragment= new fragmentstoreinformation().newinstance(merchant.getmerchantid(),merchant.getname());             break;      }     return fragment; }    @override public int getcount() {     return tabs.length; }  public string gettabview(int position) {      return tabs[position]; } 

finally, find answer. place below property in webview in xml. take webview height automatically based on content.

android:scrollbarstyle="insideoverlay" 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -