angcyo / dsltablayout Goto Github PK
View Code? Open in Web Editor NEW:hearts: Android界最万能的TabLayout(不仅仅是TabLayout), 支持任意类型的item, 支持Drawable类型的指示器,智能开启滚动,支持横竖向布局等
Home Page: https://github.com/angcyo/DslAdapter
License: MIT License
:hearts: Android界最万能的TabLayout(不仅仅是TabLayout), 支持任意类型的item, 支持Drawable类型的指示器,智能开启滚动,支持横竖向布局等
Home Page: https://github.com/angcyo/DslAdapter
License: MIT License
我这里的是在TabLayout里动态添加了3个TextView, 同时这是了tab_selected_text_size和tab_unSelected_text_size, 还有text_seleced_bold, 发现在屏幕等宽模式下, 切换一切正常, 但是在不等宽的时候, 切换Tab会出现文字抖动的情况, TextView的左右内边距我设置的是15dp. 我有2出地方是这么写的, 其中一处用的是ViewPager 这个没发现有这个问题, 但是另外一处用的是viewPager2, 就出现这个问题,
onSelectViewChange = { fromView, selectViewList, _, _ ->
// 改变字体粗细
fromView.apply {
findViewById<TextView>(R.id.classify_tag).typeface = Typeface.DEFAULT
}
selectViewList.first().apply {
findViewById<TextView>(R.id.classify_tag).typeface = Typeface.DEFAULT_BOLD
}
}
为什么fromView始终是第一项item,并没有跟随点击事件发生变化
<com.angcyo.tablayout.DslTabLayout
android:id="@+id/dslTabLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:background="#00000000"
app:tab_draw_badge="true"
app:tab_badge_gravity="center"
app:tab_badge_offset_x="50dp"
app:tab_badge_offset_y="-10dp"
app:tab_badge_solid_color="@color/color_EF393B"
app:tab_badge_text="99"
app:tab_badge_text_color="@color/white"
app:tab_badge_text_size="15sp"
app:tab_deselect_color="@color/color_333333"
app:tab_draw_indicator="true"
app:tab_indicator_color="@color/color_4975EC"
app:tab_indicator_height="1dp"
app:tab_indicator_style="STYLE_BOTTOM"
app:tab_indicator_width="MATCH_PARENT"
app:tab_orientation="HORIZONTAL"
app:tab_select_color="@color/color_4975EC">
</com.angcyo.tablayout.DslTabLayout>
通过addView添加,角标、指示器不显示
titles!!.add("地下埋设管道")
titles!!.add("地下穿越管道")
titles!!.add("架空管(桥管)")
titles!!.add("立管")
titles!!.add("法兰阀门")
titles!!.add("PE阀门")
titles!!.add("直埋焊接阀门")
titles!!.add("调压柜")
titles!!.add("调压箱")
titles!!.add("调压室")
titles!!.add("牺牲阳极")
for (s in titles) {
binding.dslTabLayout.addView(TextView(this).apply {
text = s
textSize = 14f
gravity = Gravity.CENTER_VERTICAL
layoutParams = DslTabLayout.LayoutParams(-2, -2).apply {
leftMargin = 20
rightMargin = 20
}
})
}
tab_text_view_id 属性设置多个 TextView,TextView 相同 ID 无法编译,请问如何做到的
app:tab_select_color="#F42834"
app:tab_deselect_color="@color/c6"
用下面的代码设置也是没效果的
onSelectIndexChange = { fromIndex, selectIndexList, reselect,_ ->
val toIndex = selectIndexList.first()
tabSelectColor = Color.parseColor("#F42834")
tabDeselectColor = Color.parseColor("#666666")
_viewPagerDelegate?.onSetCurrentItem(fromIndex, selectIndexList.last())
}
能帮我看一下什么问题?
场景如下:
设置3个tab item,3个item宽度长短不一,当3个item宽相加的时候并没有超过屏幕宽度,此时进行3等分,等分之后其中一个item的宽度超过了等分后的宽度,造成了布局异常。
所以应该通过最大的item宽度乘以item总数来判断是否超过屏幕宽度。
这个问题已经提了个pr,麻烦作者有空合并一下。
🙏感谢作者的开源
场景模拟:首页四个tab:A、B、C、D;在B中又有三个Tab:E、F、G。现在点击A中的一个按钮,同时发出事件a,b。a定位首页的tab到B;b事件定位到B中的G。由于事件a、b是同时发出的,会存在B页面还没可见的时候就会触发b事件。这个时候setCurrentItem就会出现死循环,并且B中的定位回调失效。延时500ms执行setCurrentItem就没事。
/**设置tab的位置*/
fun setCurrentItem(index: Int, notify: Boolean = true, fromUser: Boolean = false) {
if (currentItemIndex == index) {
_scrollToCenter(index, tabIndicator.indicatorAnim)
return
}
val targetView = dslSelector.visibleViewList.getOrNull(index)
if (targetView == null || ViewCompat.isLaidOut(targetView)) {
dslSelector.selector(index, true, notify, fromUser)
} else {
post {
//逻辑一直执行这里
setCurrentItem(index, notify, fromUser)
}
}
}
库是好库,只是这个文档看得我一脸懵逼,希望可以规范完善一下,可以省了很多接入的时间。
这几个属性对imageview不生效,只对文字有效,指示器也没有显示
这是我的xml
<com.angcyo.tablayout.DslTabLayout
android:id="@+id/dslTabLayout"
android:layout_width="match_parent"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:tab_draw_indicator="true"
app:tab_indicator_color="@color/colorPrimary"
app:tab_item_is_equ_width="true"
app:tab_select_color="@color/colorPrimary"
app:tab_deselect_color="#626262">
onSelectIndexChange
调用后,可能会导致tab点击切换viewPager失效?
源码:
tabLayoutConfig?.onSelectIndexChange?.invoke(fromIndex, selectList, reselect)
?: _viewPagerDelegate?.onSetCurrentItem(fromIndex, toIndex)
通过setCurrentItem更新下标,onSelectItemView回调返回的index和View依然是原先的下标
使用 mTabLayout.setCurrentItem(index); 方法指定滑动到超出屏幕的某个位置时,item被选中了,但是tablayout内部没有滑动到选中的位置使其显示在屏幕上
请问在切换的过程中,是否支持动态更新字体和下划线的颜色呢?
源码中这个类貌似没用到,版主可否给个示例。
通过XML配置
app:tab_text_min_size="20sp"
app:tab_text_max_size="25sp"
app:tab_select_color="@color/themeTextColor"
app:tab_deselect_color="@color/textColorGray"
这些属性都无效,但是我通过代码配置config滑动事件改变颜色有效
首先库是好库,根据属性大全用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()
DslTabLayout 能做到这种效果吗,或者说有没有什么接口可以快速实现
https://github.com/Ultrahuman-tech/SmartTabLayout
动态添加tab好像是通过 tabLayout.addView()
配置属性好像有点麻烦。
demo里面的add item能做到跟demo主页的效果吗
DslTabLayout#currentItemIndex判断获取到对应的索引,结果获取到了-1。非必现。
请问使用的时候是每次需要我在 xml 创建 TextView 吗?没有和 viewPager1 的标题关联吗?我在示例中没有找到相关的配置呢
这里高凸tab貌似用clipChildren实现 没有点击回调 有什么好的解决方案吗
要求:1. 只有打开对应tab的时候才加载fragment 2.加载后不回收。
不太喜欢官方提供的;�Tab+ViewPager要么会回收,要么会预加载,要么一次全部加载。
现在有个需求,要做成内部可以滑动,我太难了
kotlin看不明白=.=
app:tab_deselect_color="@color/text_gray"
app:tab_select_color="@color/TextColorBlack"
这两个xml属性在Java代码是哪个方法可以设置?
角标可以加个边框颜色和粗细的属性吗
首先感谢作者,目前看来这个库很强大,有望成为下一个热点。
library版本:V1.5.2,用的viewpager2。
使用时所有属性都在layout里面设置,开启 tab_enable_gradient_color = true 之后,viewpager滑动切换tab无问题;但是当点击切换tab时,被点击tab未能达到预设颜色,会比预设颜色暗一些(个人猜测:可能是点击未处理好颜色的切换问题)。然后再滑动viewpager2就正常,或者说稍微动一下viewpager2就又正常。
麻烦有时间看一下。在回调里面通过DslTabLayout 获取索引获取的是不对的,但是回调的值 index
是对的。
代码如下,获取索引不对:
`
desLayout.configTabLayoutConfig {
onSelectItemView = { _, index, select, _ ->
Log.d("desLayout", "titles2DslTabLayoutChildren: " + select + "," + index)
if (select) {
//这里获取索引不对。
val currentItemIndex =dslLayout .currentItemIndex
}
false
}
}
`
rt
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/click_bg">
<ImageView
android:layout_width="wrap_content"
android:layout_height="21dp"
android:adjustViewBounds="true"
android:src="@mipmap/module_msg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="消息"
android:textSize="11dp"
android:layout_marginTop="4dp"
android:textColor="@color/gray_33"/>
</LinearLayout>
像这种,linearLayout里一个imageView和一个textView,tab_select_color和tab_deselect_color设置无效是吗?
如果是像阿拉伯语这种需要左右颠倒的语言,需要怎样做比较好?动态添加TextView然后改变数据源吗
removeAllViews之后重新addView,点击item时提示List is null
作者有没有提供低版本的啊
当我的item没有铺满整个屏幕时,dsltablayout是不可滑动的 ,而这是我点击最后一个tab后切换成小窗状态,这时item数量超出了屏幕,是可以滑动的,这时再从小窗切换回全屏状态,dsltablayout不可滑动且把前几个item顶出了屏幕,滑不回来了,具体情况可以看链接里的录屏
https://dl.muge.info/WeChat_20211105214806.mp4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.