ViewPagerIndicator - 将TabPageIndicator设置为中心

8
我正在制作一个的时间表应用程序,并使用ViewPagerIndicator作为片段。但是现在我有一个问题,我想让TabPageIndicator居中。就像这样: Example

我想设置单个选项卡的宽度和高度。并将该选项卡设置为支持选定/按下状态的可绘制对象。

我还没有找到解决这些问题的方法。我尝试过使用onPageSelectedContextThemeWrapper,但那并没有起作用。(也许我没有正确使用它)。

是否可以实现所有这些功能,或者我应该查看其他东西而不是ViewPagerIndicator?(也欢迎使用其他不带ViewPagerIndicator的选项)。

图像上的应用程序是Untis Mobile,可以在PlayStore上找到。 我已经询问了创建者他们如何做到这一点,但他们说该应用程序不是开源的。(但我在源代码中发现他们使用TwoDScrollView,但我不确定) 编辑: 样式已使用vpiTabPageIndicatorStyle进行修复。(在XDA Developers的帮助下!) 当我添加20个项目时,它会停留在中间,但只有从第4项到第17项,第1、2、3、18、19、20项不在中间。请参见:

Wrong

我可以添加3个空项(或空格),以确保第一个和最后一个项目位于中间吗?就像这样(来自Untis移动应用程序):

Good

(我已经尝试在vpiTabPageIndicatorStyle中使用android:paddingLeft,但没有效果)

我知道viewPager.setCurrentItem(total/2)会将TabPageIndicator设置在中间,但它停留在中间,我无法选择其他日期(我在onPageScrolled中调用它)。所以当你滚动时,选定的需要在中间。这可行吗?

3个回答

5
您要查找的小部件类似于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>

设置一个监听器到滚轮视图,当变化发生时,您可以将您的片段放在活动中的帧布局中。


-1

使用方法如下:

TabPagerIndicator tbi;
   ViewPager pager;

onCreate() 中这样做

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

希望这对你有用。 :D


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接