如何在 android 中正确显示 ViewPager/TitlePageIndicator 中的整个上一个和下一个标题

How to show correctly whole previus and next titles in ViewPager/TitlePageIndicator in android

我正在使用 ViewPager 和 TitlePageIndicator。我的问题是我想在屏幕上显示三个标题。可以看到图中右边的标题被切掉了

我该怎么做?我尝试过这个但它不起作用...

pager.setClipToPadding(false);
    pager.setPadding(40, 0, 40, 0);
    pager.setPageMargin(20);

提前致谢:

这是 ViewPager 和 TitlePageIndicator 的代码:

this.pager = (ViewPager) this.findViewById(R.id.pager);

TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
        final float density = getResources().getDisplayMetrics().density;
        indicator.setFooterColor(R.color.setTextColor);
        indicator.setFooterLineHeight(1 * density); //1dp
        indicator.setFooterIndicatorHeight(3 * density); //3dp
        indicator.setFooterIndicatorStyle(TitlePageIndicator.IndicatorStyle.Underline);
        indicator.setTextColor(0xAA000000);
        indicator.setSelectedColor(R.color.setTextColor);
        indicator.setSelectedBold(true);
        indicator.setViewPager(pager);

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

尝试将此添加到您的 xml:

  <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <android.support.v4.view.PagerTabStrip
            android:id="@+id/pager_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"/>
    </android.support.v4.view.ViewPager>