【发布时间】:2012-04-17 23:53:04
【问题描述】:
有谁知道如何像主屏幕上的那样设置页面/查看计数器(小点)的示例?
像这个例子:
谢谢
【问题讨论】:
-
你使用的是
ViewPager还是什么? -
是的,我是。我基本上遵循了这个例子developer.android.com/resources/samples/Support4Demos/src/com/…
标签: android
有谁知道如何像主屏幕上的那样设置页面/查看计数器(小点)的示例?
像这个例子:
谢谢
【问题讨论】:
ViewPager还是什么?
标签: android
PagerTitleStrip 是您与ViewPager 一起使用的,用于指示您当前所在的页面。这是您添加到 XML 的内容。
布局 XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<android.support.v4.view.PagerTitleStrip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
</LinearLayout>
在您的 PagerAdapter 中:
@Override
public CharSequence getPageTitle (int position) {
return "Your static title";
}
不过,PagerTitleStrip 的可定制性不高,但 ViewPagerIndicator 可定制性很强,并且包含您正在寻找的虚线指示符。您需要对其进行主题化以在 OP 中重新创建图片。
圆圈指示器与 ViewPagerIndicator:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.viewpagerindicator.sample"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
然后在你的代码中:
CirclePageIndicator mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
ViewPagerExtensions 是另一个开源库,它为您可能感兴趣的ViewPager 提供自定义视图。
【讨论】:
CirclePagerIndicator 的例子。我不明白你遇到了什么麻烦。就文档而言,我只知道我在谷歌上搜索的内容。