TabLayout

作者: Amy木婉清 | 来源:发表于2020-09-16 09:31 被阅读0次

    TabLayout一般配合ViewPager使用,实现底部table或中间table等左右滑动的操作.
    Tablayout继承自HorizontalScrollView,用作页面切换指示器,因使用简便功能强大而广泛使用在App中。
    使用步骤:
    1.添加依赖:

    implementation ‘com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar’ 
    

    在xml中使用

        <com.flyco.tablayout.SlidingTabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimens_44dp"
            android:layout_marginRight="8dp"
            tl:tl_indicator_color="@color/normalPrimary"
            tl:tl_indicator_gravity="BOTTOM"
            tl:tl_indicator_height="4dp"
            tl:tl_indicator_style="NORMAL"
            tl:tl_indicator_width_equal_title="false"
            tl:tl_tab_padding="12dp"
            tl:tl_tab_space_equal="true"
            tl:tl_textSelectColor="@color/normalPrimary"
            tl:tl_textUnselectColor="@color/color_black4"
            />
    

    Activity中使用:

     private ViewPager viewPager;
     smartTabLayout = findViewById(R.id.smart);
     smartTabLayout.setViewPager(viewPager);//绑定tab和viewPager
    

    注:tl是自定义的 在xml上方要用xmlns:tl="http://schemas.android.com/apk/res-auto",否则不予生效
    其中里面关于tl的属性具体介绍如下:
    属性 格式 描述
    tl_indicator_color color 设置指示器颜色
    tl_indicator_height dimension 设置指示器高度
    tl_indicator_width dimension 设置指示器固定宽度
    tl_indicator_margin_left dimension 设置指示器margin,当indicator_width大于0,无效
    tl_indicator_margin_top dimension 设置指示器margin,当indicator_width大于0,无效
    tl_indicator_margin_right dimension 设置指示器margin,当indicator_width大于0,无效
    tl_indicator_margin_bottom dimension 设置指示器margin,当indicator_width大于0,无效
    tl_indicator_corner_radius dimension 设置指示器圆角弧度
    tl_indicator_gravity enum 设置指示器上方(TOP)还是下方(BOTTOM),只对常规指示器有用
    tl_indicator_style enum 设置指示器为常规(NORMAL)或三角形(TRIANGLE)或背景色块(BLOCK)
    tl_underline_color color 设置下划线颜色
    tl_underline_height dimension 设置下划线高度
    tl_underline_gravity enum 设置下划线上方(TOP)还是下方(BOTTOM)
    tl_divider_color color 设置分割线颜色
    tl_divider_width dimension 设置分割线宽度
    tl_divider_padding dimension 设置分割线的paddingTop和paddingBottom
    tl_tab_padding dimension 设置tab的paddingLeft和paddingRight
    tl_tab_space_equal boolean 设置tab大小等分
    tl_tab_width dimension 设置tab固定大小
    tl_textsize dimension 设置字体大小
    tl_textSelectColor color 设置字体选中颜色
    tl_textUnselectColor color 设置字体未选中颜色
    tl_textBold boolean 设置字体加粗

    相关文章

      网友评论

          本文标题:TabLayout

          本文链接:https://www.haomeiwen.com/subject/oyfqyktx.html