繁体   English   中英

无法修复Android中的PagerTitleStrip

[英]Not able to fix PagerTitleStrip in android

PagerTitleStrip正在溢出。 我一次看不到所有标题。 无法找出我在这里想念的东西。 我已附上屏幕截图。 PageTitleStripExample-无法同时看到3个标题。

另外,我如何向这些选项卡添加重要的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM