【问题标题】:PagerSlidingTabStrip selected tab line at topPagerSlidingTabStrip 在顶部选定的选项卡行
【发布时间】:2016-02-29 12:55:54
【问题描述】:

我正在使用库 PagerSlidingTabStrip 来获取 ViewPager 中标题的动态数量。这是一个很棒的库,易于使用,但我需要对其进行更多定制。

我的 PagerSlidingTabStrip 标题位于屏幕底部,因此,我需要 PagerSlidingTabStrip 组件顶部的“全宽下划线”和“选定项目行指示器”。

经过一些测试,我终于将“全宽下划线”放在正确的位置,使用这样的辅助 LinearLayout:

<LinearLayout
        android:id="@+id/tabs_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:orientation="vertical"
            android:background="@color/lfp_yellow"/>

        <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="48dip"
            app:pstsDividerColor="@android:color/transparent"
            app:pstsIndicatorColor="@color/light_yellow"
            app:pstsIndicatorHeight="4px"
            app:pstsShouldExpand="true"/>
    </LinearLayout>

但我还没有将“选定项目行指示器”放在顶部。我尝试使用顶部有一条线的可绘制对象更改所选项目背景,但没有工作:(

有什么想法吗?

非常感谢。

【问题讨论】:

    标签: android android-viewpager pagerslidingtabstrip


    【解决方案1】:

    我终于找到了解决方案,但需要对库代码进行一些更改。

    首先,我们需要在项目中添加库代码,而不是通常的外部依赖:

    dependencies {
     compile 'com.jakewharton:butterknife:6.0.0'
    }
    

    为此,在我们的 Android Studio 项目中导入库项目有一个非常有用的教程。此外,在本教程中,它使用这个 PagerSlidingTabStrip 库作为示例! (完美!)

    How do I add a library project to Android Studio?

    之后,我们只需要打开 PagerSlidingTabStrip.java 文件并转到 'onDraw' 函数。

    我们必须改变这一行:

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    

    对于这个:

    canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight , rectPaint);
    

    它已经完成了!

    另一方面,如果你有兴趣修改这个库,也许你会发现这个修改也很有用(将来可能会包含在库的 master 分支中):

    https://github.com/astuetz/PagerSlidingTabStrip/pull/62/files?short_path=04c6e90

    我希望这对某人有用:)

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      相关资源
      最近更新 更多