[英]Not able to fix PagerTitleStrip in android
PagerTitleStrip正在溢出。 我一次看不到所有標題。 無法找出我在這里想念的東西。 我已附上屏幕截圖。
另外,我如何向這些選項卡添加重要的UI主題。 哪個庫是必需的,以及如何將主題應用於選項卡或整個應用程序
我的適配器代碼
public class MyAdapter extends FragmentPagerAdapter
{
int totalFragments = 3;
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return MyFragment.newInstance(position);
}
@Override
public int getCount() {
return totalFragments;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Tab One";
case 1:
return "Tab Two";
case 2:
return "Tab Three";
}
return null;
}
}
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:scrollbarSize="200dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
首先,在不使用fill_parent
地方,請使用fill_parent
,將其替換為match_parent
。
其次, ViewPager
大小的常用設置是
android:layout_width="match_parent"
android:layout_height="0px"
並且可能
android:layout_weight="1"
在這些之后,為您的PagerTitleStrip
嘗試
android:layout_width="wrap_content"
第三,設計選項卡式TabLayout
的實質方法是使用TabLayout
,Google為其提供了一些教程和示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.