我正在使用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>
答案 0 :(得分:0)
尝试在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>