ViewPagerIndicator - Set the TabPageIndicator to the center

半世苍凉 提交于 2019-12-12 07:57:13

问题


I make an timetable application for android and I'm using ViewPagerIndicator as fragment. But now I've a problem, I want to get the TabPageIndicator to the center. Like this:

And I would to like to set the individual tab width and height. And set that tab to a drawable that support selected/pressed states.

I've not found it yet to solve these problems. I've try something with onPageSelected and ContextThemeWrapper but that doesn't work. (Maybe I'm not using it correctly).

Is this all possible to make or should I look to something else than ViewPagerIndicator? (An other option without ViewPagerIndicator is also welcome).

The app on the image is Untis Mobile and can be found on the PlayStore. I've already ask the creators how they do it but they said the app isn't open source. (But I have found in the source that they do it with TwoDScrollView, but I'm not sure)

Edit:

The styling is fixed with vpiTabPageIndicatorStyle. (With help of XDA Developers!)

When I add 20 items it stays on the middle but only from item 4 to item 17, item 1, 2, 3, 18, 19, 20 are not in the middle. See:

Can I add a 3 empty items (or empty space) to ensure that the first and last items are in the middle? Something like this (from the Untis Mobile app):

(I've already tried android:paddingLeft in vpiTabPageIndicatorStyle but that doesn't work)

I know that viewPager.setCurrentItem(total/2) will set the TabPageIndicator in the middle but then it stays on the middle and I'm not able to select a other day (I call it in onPageScrolled). So I want as you scroll the selected one needs to be in the middle. Is this possible?


回答1:


The widget you are looking for is similar to the android horizontal wheel. There is an implementation at android-spinnerwheel which can be what you need.




回答2:


Then you don't need an viewpagerindicator. Use a horizontal scroll view as Amulya Khare suggested in your activity and replace fragments when scrolling occurs.

Your activity layout could be like :

<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>

Set a listener to wheelview and when change occurs you can put your fragments in framelayout in your activity.




回答3:


Use it like this :

TabPagerIndicator tbi;
   ViewPager pager;

in onCreate() do like this

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

I hope this will work out for you. :D



来源:https://stackoverflow.com/questions/19764866/viewpagerindicator-set-the-tabpageindicator-to-the-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!