【问题标题】:ViewPagerIndicator - Set the TabPageIndicator to the centerViewPagerIndicator - 将 TabPageIndicator 设置为中心
【发布时间】:2013-11-04 09:34:37
【问题描述】:

我为 做了一个时间表申请,我使用ViewPagerIndicator 作为片段。但是现在我有一个问题,我想将 TabPageIndicator 放在中心。像这样:

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

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

这一切都可能实现吗,还是我应该寻找除 ViewPagerIndicator 之外的其他东西? (也欢迎使用不带 ViewPagerIndicator 的其他选项)。

图片上的应用是 Untis Mobile,可以在 PlayStore 上找到。 我已经问过创作者他们是怎么做的,但他们说这个应用程序不是开源的。 (但我在源代码中发现他们使用TwoDScrollView 进行操作,但我不确定)

编辑:

样式用vpiTabPageIndicatorStyle 固定。 (在 XDA 开发人员的帮助下!)

当我添加 20 个项目时,它停留在中间,但仅从项目 4 到项目 17,项目 1、2、3、18、19、20 不在中间。见:

我可以添加 3 个空项目(或空白空间)以确保第一个和最后一个项目在中间吗?像这样的东西(来自 Untis 移动应用程序):

(我已经在vpiTabPageIndicatorStyle 中尝试过android:paddingLeft 但这不起作用)

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

【问题讨论】:

    标签: android java android horizontalscrollview android-scrollview viewpagerindicator


    【解决方案1】:

    您正在寻找的小部件类似于 android 水平轮。 android-spinnerwheel 有一个实现,可以满足您的需要。

    【讨论】:

      【解决方案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 设置监听器,当发生变化时,您可以将片段放入 Activity 的框架布局中。

      【讨论】:

        【解决方案3】:

        像这样使用它:

        TabPagerIndicator tbi;
           ViewPager pager;
        

        onCreate() 这样做

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

        我希望这对你有用。 :D

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-01-09
          • 1970-01-01
          相关资源
          最近更新 更多