2012-04-04 70 views
4

有沒有人知道如何在主屏幕上執行頁面/查看計數器(小點)的示例?Android在主屏幕上實現頁面計數器

像這個例子:

enter image description here

感謝

+0

你使用'V iewPager'還是什麼? – adneal 2012-04-04 09:21:55

+0

是的。我基本上遵循這個例子http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.html – 2012-04-04 09:43:53

回答

7

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你可能會感興趣。

+0

謝謝,這可能正是我需要的。 – 2012-04-04 09:57:23

+0

我無法完成工作,JakeWarton上的項目似乎並不容易配置。你有任何其他文件可以幫助嗎? – 2012-04-05 17:53:45

+0

這非常容易,我相信你會得到它的工作。以下是[ViewPagerIndicator網站](http://viewpagerindicator.com/#usage)的鏈接,以及指向[一系列定製化文章的鏈接]的鏈接。(http://blog.stylingandroid.com/archives/537) – adneal 2012-04-05 18:34:15