9

我爲製作了時間表應用程序,我使用ViewPagerIndicator作爲片段。但是現在我遇到了問題,我想讓TabPageIndicator居中。像這樣: ExampleViewPagerIndicator - 將TabPageIndicator設置爲中心

而且我想設置單個標籤的寬度和高度。並將該選項卡設置爲支持選定/按下狀態的繪圖。

我還沒找到解決這些問題的方法。我嘗試了onPageSelectedContextThemeWrapper,但這不起作用。 (也許我沒有正確使用它)。

這一切都可能使我還是應該尋找除ViewPagerIndicator之外的其他東西? (另外一個沒有ViewPagerIndicator的選項也是可以的)。

圖像上的應用程序是Untis Mobile,可以在PlayStore上找到。 我已經問過創作者他們是怎麼做的,但他們說這個應用不是開源的。 (但我在他們與TwoDScrollView做源中找到,但我不知道)

編輯:

的造型是固定的vpiTabPageIndicatorStyle。 (在XDA開發者的幫助下!)

當我添加20個項目時,它停留在中間,但僅從項目4到項目17,項目1,2,3,18,19,20不在中間。請參閱:

Wrong

我可以添加3級空的物品(或空的空間),以確保第一項和最後一項是在中間?像這樣的事情(從條約資料系統手機應用程序):

Good

(我已經嘗試過android:paddingLeftvpiTabPageIndicatorStyle但不工作)

我知道viewPager.setCurrentItem(total/2)將設置TabPageIndicator在中間,但它保持在中間,我無法選擇其他日子(我在onPageScrolled中稱之爲)。所以我想當你滾動選中的一個需要在中間。這可能嗎?

回答

6

您正在尋找的小工具類似於android水平輪。在android-spinnerwheel有一個實現,它可以是你需要的。

enter image description here

2

那麼你並不需要一個viewpagerindicator。在您的活動中使用Amulya Khare建議的水平滾動視圖,並在發生滾動時更換碎片。

你的活動佈局可能是這樣的:

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <SomeWheelView 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      /> 
     <SomeStaticIndicatorView 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      /> 
     <FrameLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      /> 
</LinearLayout> 

設置一個監聽wheelview,當變化發生時,你可以把你的片段中的FrameLayout您的活動。

-1

使用這樣的:

TabPagerIndicator tbi; 
    ViewPager pager; 

onCreate()做這樣

tbi=(TabPagerIndicator)findViewById(R.id.something); 
    tbi.setViewPager(pager); 

我希望這將制定出適合您。 :D

相關問題