angcyo / DslTabLayout

:hearts: Android界最万能的TabLayout(不仅仅是TabLayout), 支持任意类型的item, 支持Drawable类型的指示器,智能开启滚动,支持横竖向布局等
https://github.com/angcyo/DslAdapter
MIT License
1.55k stars 145 forks source link

关于初始化配置(代码配置) #35

Closed Joslyn-Chen closed 3 years ago

Joslyn-Chen commented 3 years ago

首先库是好库,根据属性大全用xml配置也没问题。 现在我用一个类继承DslTabLayout,然后在init里面初始化一些配置。 1、角标配置失败。(onTabBadgeConfig配置也不生效,wiki里面好像是单一配置,统一配置不行,希望像xml配置一次就行了)

    drawBadge = true
    tabBadge = DslTabBadge().apply {
      updateBadgeConfig(
        TabBadgeConfig(
          badgeTextSize = 10 * dp,
          badgeTextColor = Color.WHITE,
          badgeSolidColor = context.getCompatColor(color.user_badge_color),
          badgeGravity = Gravity.RIGHT or Gravity.TOP,
          badgeCircleOffsetX = 6 * dpi,
          badgeCircleOffsetY = 8 * dpi,
          badgeOffsetX = 8 * dpi,
          badgeOffsetY = 18 * dpi
        )
      )
    }

2、Indicator需要配置两次才能生效。(比如高宽和Offset,是因为他们的默认值不是本身?)

    drawIndicator = true
    tabIndicator = DslTabIndicator(this).apply {
      indicatorHeight = 2 * dpi
      indicatorWidth = 40 * dpi
      indicatorHeightOffset = 1 * dpi
      indicatorYOffset = -1 * dpi
      indicatorStyle = DslTabIndicator.INDICATOR_STYLE_BOTTOM
      indicatorEnableFlow = true
      gradientShape = GradientDrawable.RECTANGLE
      gradientSolidColor = context.getCompatColor(color.user_red_important)
    }
    tabIndicator.apply {
      indicatorHeight = 2 * dpi
      indicatorWidth = 40 * dpi
      indicatorHeightOffset = 1 * dpi
      indicatorYOffset = -1 * dpi
      indicatorStyle = DslTabIndicator.INDICATOR_STYLE_BOTTOM
      indicatorEnableFlow = true
      gradientShape = GradientDrawable.RECTANGLE
      gradientSolidColor = context.getCompatColor(color.user_red_important)
    }
    invalidate()
angcyo commented 3 years ago

1: 角标的默认配置请使用DslTabBadgedefaultBadgeConfig

2:Indicator的部分属性, 会根据TabLayout的横竖向智能设置, 所以此时的初始化值会无效. 等待初始化结束之后, 可以直接操作属性进行覆盖.