|
|
@@ -33,6 +33,7 @@ class ExpandableTabLayout(private val ctx: Context, attrs: AttributeSet) :
|
|
|
private var mOnSelectListener: OnSelectListener? = null
|
|
|
private var isInteractive = false
|
|
|
private var mSelectIndex = 0
|
|
|
+ private var mDirection: Int = DOWNWARDS
|
|
|
|
|
|
init {
|
|
|
val root = View.inflate(ctx, R.layout.layout_expandable_tab_layout, this)
|
|
|
@@ -40,10 +41,12 @@ class ExpandableTabLayout(private val ctx: Context, attrs: AttributeSet) :
|
|
|
|
|
|
val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.ExpandableTabLayout)
|
|
|
|
|
|
- val direction = attrSet.getInt(R.styleable.ExpandableTabLayout_expand_direction, 0)
|
|
|
- if (direction == 1) {
|
|
|
+ mDirection = attrSet.getInt(R.styleable.ExpandableTabLayout_expand_direction, DOWNWARDS)
|
|
|
+ if (mDirection == UPWARDS) {
|
|
|
mBinding.ivAction.rotation = 180f
|
|
|
- mBinding.root.background = AppCompatResources.getDrawable(ctx, R.drawable.expandable_tab_bg_bottom)
|
|
|
+ mBinding.root.setBackgroundResource(R.drawable.expandable_tab_bg_bottom)
|
|
|
+ } else {
|
|
|
+ mBinding.root.setBackgroundResource(R.drawable.expandable_tab_bg_top)
|
|
|
}
|
|
|
|
|
|
// 是否要联动下划线
|
|
|
@@ -74,9 +77,11 @@ class ExpandableTabLayout(private val ctx: Context, attrs: AttributeSet) :
|
|
|
holder.setText(R.id.tv_name, it)
|
|
|
}
|
|
|
holder.setOnClickListener(R.id.root) {
|
|
|
- mOnSelectListener?.onSelect(position)
|
|
|
- mBinding.rvTab.adapter?.notifyDataSetChanged()
|
|
|
- mSelectIndex = position
|
|
|
+ if (isInteractive) {
|
|
|
+ mOnSelectListener?.onSelect(position)
|
|
|
+ mBinding.rvTab.adapter?.notifyDataSetChanged()
|
|
|
+ mSelectIndex = position
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -106,7 +111,11 @@ class ExpandableTabLayout(private val ctx: Context, attrs: AttributeSet) :
|
|
|
}
|
|
|
isCollapse = !isCollapse
|
|
|
|
|
|
- mBinding.ivAction.rotation = if (isCollapse) 0f else 180f
|
|
|
+ mBinding.ivAction.rotation = if (isCollapse) {
|
|
|
+ if (mDirection == DOWNWARDS) 0f else 180f
|
|
|
+ } else {
|
|
|
+ if (mDirection == DOWNWARDS) 180f else 0f
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|