TabPageIndicator does not match the correct location inside the fragment

I am trying to put com.viewpagerindicator.TabPageIndicator in a SherlockFragment . Although scrolling content in ViewPager works very well, the TabPageIndicator style does not work correctly. This pager contains five fragments, and their names will not match the width of the screen. This works fine for me in Activity, but when I try to use it in the Fragment, all five names were cut off to fit the width of the screen.

I tried using both LayoutInflater provided in Fragment#onCreateView and getSystemService , both results produce the same result.

Not sure if this is related, but I also have com.actionbarsherlock.widget.SearchView in this layout and all attributes have not been applied.

my_search_layout.xml

  <com.viewpagerindicator.TabPageIndicator android:id="@+id/indicator" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:layout_below="@id/indicator" /> </RelativeLayout> 

MySearchFragment

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutInflater themedInflater = (LayoutInflater) getSherlockActivity() .getSupportActionBar() .getThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = themedInflater.inflate(R.layout.my_search_layout, container, false); FragmentManager fm = ((Fragment)this).getChildFragmentManager(); mSectionsPagerAdapter = new SectionsPagerAdapter(fm); mViewPager = (ViewPager) root.findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); TabPageIndicator indicator = (TabPageIndicator) root.findViewById(R.id.indicator); indicator.setViewPager(mViewPager); return root; } 

SectionsPagerAdapter

 public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { Fragment fragment = null; Log.d(TAG, "SectionsPagerAdapter: " + i); fragment = new HelloFragment(); return fragment; } @Override public int getCount() { return 5; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return getString(R.string.section_title_page_1); case 1: return getString(R.string.section_title_page_2); case 2: return getString(R.string.section_title_page_3); case 3: return getString(R.string.section_title_page_4); case 4: return getString(R.string.section_title_page_5); } return null; } } 
+4
source share

All Articles