android - TabHost tabs are not horizontally scrolling when swiping using ViewPager -
i writing app uses many fragments. have used actionbarsherlock (with actionbar). work-around bug #240, i've decided switch functionally working implementation use actionbarsherlock tabhost. after half few hours of work, working fine, except when swiping between pages: correspondent tab selected, not centered , not visible user can't see tab selected.

in picture can see visible fragment ("weekly s..") tab only half visible. next swipe make "weekly s..." "calendar events" , won't know tab selected unless swipe tabwidget manually.
here activity_main.xml:
<tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <horizontalscrollview android:layout_width="wrap_content" android:layout_height="wrap_content" android:fillviewport="true" android:scrollbars="none" > <tabwidget android:id="@android:id/tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tabstripenabled="true" android:orientation="horizontal" /> </horizontalscrollview> <framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="0"/> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </linearlayout> </tabhost> and tabsadapter same jake wharton's example of fragmenttabspager.
any suggestions welcome!
thanks post, , jucas in particular, managed work. here code:
@override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { view tabview = mtabhost.gettabwidget().getchildat(position); if (tabview != null) { final int width = mhorizontalscroll.getwidth(); final int scrollpos = tabview.getleft() - (width - tabview.getwidth()) / 2; mhorizontalscroll.scrollto(scrollpos, 0); } else { mhorizontalscroll.scrollby(positionoffsetpixels, 0); } } of course had mhorizontalscroll initialized in several places. (if isn't sure how it, i'll happy post full code.)
Comments
Post a Comment