に入れようとしcom.viewpagerindicator.TabPageIndicator
ていSherlockFragment
ます。コンテンツのスクロールはViewPager
非常にうまく機能しますが、TabPageIndicator のスタイル設定は適切に機能していません。このページャには 5 つのフラグメントが含まれており、それらのタイトルは画面の幅に収まりません。Activity では問題なく動作していますが、Fragment でこれを使用しようとすると、5 つのタイトルすべてが画面の幅に合わせて切り取られました。
LayoutInflater
提供されている両方を使用してみましたがFragment#onCreateView
、getSystemService
両方とも同じ結果になりました。
関連するかどうかはわかりませんが、このレイアウトには com.actionbarsherlock.widget.SearchView もあり、すべての属性が適用されませんでした。
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>
マイサーチフラグメント
@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;
}
セクションPagerAdapter
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;
}
}