如果我第一次向您展示屏幕截图,它会更容易: Here is the picture of my screen
我在viewPager上使用TabPageIndicator。我在viewPager中只有两个页面。 标题显示在顶部,但没有标签的图片。你无法看到你关注的是哪一个。喜欢它应该。 for example here
我已经搜索了很长时间,但无法成功。谢谢你的帮助。
这是一些代码(我不确定你是否需要它):
ViewPager viewPager = (ViewPager)findViewById(R.id.distance_viewpager);
adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
TabPageIndicator titleIndicator = (TabPageIndicator) findViewById(R.id.titles);
titleIndicator.setViewPager(viewPager);
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private Fragment[] FRAGMENTS = null;
final String[] page_titles = new String[]{"Location One", "Location Two"};
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
PlaceOneFragment placeOneFragment = new PlaceOneFragment();
PlaceTwoFragment placeTwoFragment = new PlaceTwoFragment();
FRAGMENTS = new Fragment[getCount()];
FRAGMENTS[0] = placeOneFragment;
FRAGMENTS[1] = placeTwoFragment;
}
@Override
public Fragment getItem(int position) {
return FRAGMENTS[position];
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
return page_titles[position];
}
}
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Distance.DistanceActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe to choose your two locations"/>
<View
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:background="#000000"
android:layout_height="1dp"/>
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/titles"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<android.support.v4.view.ViewPager
android:id="@+id/distance_viewpager"
android:layout_width="match_parent"
android:layout_height="300dp">
</android.support.v4.view.ViewPager>