|
@@ -0,0 +1,99 @@
|
|
|
|
|
+package com.grkj.iscs_mc.view.widget
|
|
|
|
|
+
|
|
|
|
|
+import android.content.Context
|
|
|
|
|
+import android.util.AttributeSet
|
|
|
|
|
+import android.view.Gravity
|
|
|
|
|
+import android.view.View
|
|
|
|
|
+import android.widget.ImageView
|
|
|
|
|
+import android.widget.LinearLayout
|
|
|
|
|
+import android.widget.RelativeLayout
|
|
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager
|
|
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
+import com.grkj.iscs_mc.R
|
|
|
|
|
+import com.grkj.iscs_mc.databinding.LayoutExpandableTabLayoutBinding
|
|
|
|
|
+import com.grkj.iscs_mc.util.ToastUtils
|
|
|
|
|
+import com.zhy.adapter.recyclerview.CommonAdapter
|
|
|
|
|
+import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 伸缩/展开 Tab列表
|
|
|
|
|
+ */
|
|
|
|
|
+class ExpandableTabLayout(private val ctx: Context, attrs: AttributeSet) :
|
|
|
|
|
+ RelativeLayout(ctx, attrs) {
|
|
|
|
|
+
|
|
|
|
|
+ companion object {
|
|
|
|
|
+ const val DOWNWARDS = 0
|
|
|
|
|
+ const val UPWARDS = 1
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private var mBinding: LayoutExpandableTabLayoutBinding
|
|
|
|
|
+ private var isCollapse = true
|
|
|
|
|
+
|
|
|
|
|
+ init {
|
|
|
|
|
+ val root = View.inflate(ctx, R.layout.layout_expandable_tab_layout, this)
|
|
|
|
|
+ mBinding = LayoutExpandableTabLayoutBinding.bind(root)
|
|
|
|
|
+
|
|
|
|
|
+ val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.ExpandableTabLayout)
|
|
|
|
|
+
|
|
|
|
|
+ val direction = attrSet.getInt(R.styleable.ExpandableTabLayout_expand_direction, 0)
|
|
|
|
|
+ if (direction == 1) {
|
|
|
|
|
+ mBinding.ivAction.rotation = 180f
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val interactive = attrSet.getBoolean(R.styleable.ExpandableTabLayout_interactive, true)
|
|
|
|
|
+ // TODO tab下划线
|
|
|
|
|
+
|
|
|
|
|
+ val title = attrSet.getString(R.styleable.ExpandableTabLayout_expand_title)
|
|
|
|
|
+ title?.let {
|
|
|
|
|
+ mBinding.tvTitle.text = title
|
|
|
|
|
+ } ?: let {
|
|
|
|
|
+ mBinding.tvTitle.visibility = View.GONE
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ attrSet.recycle()
|
|
|
|
|
+
|
|
|
|
|
+ mBinding.rvTab.adapter =
|
|
|
|
|
+ object : CommonAdapter<String>(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ R.layout.item_rv_expandable_tab,
|
|
|
|
|
+// mutableListOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56","57", "58", "59", "60", "61")
|
|
|
|
|
+ mutableListOf()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ override fun convert(holder: ViewHolder, t: String, position: Int) {
|
|
|
|
|
+ holder.getView<ImageView>(R.id.iv_icon).setImageResource(R.mipmap.safety_helmet)
|
|
|
|
|
+ holder.setText(R.id.tv_name, "安全帽($t)")
|
|
|
|
|
+ holder.setOnClickListener(R.id.root) {
|
|
|
|
|
+ ToastUtils.tip("点击了$t")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mBinding.rvTab.isNestedScrollingEnabled = false
|
|
|
|
|
+
|
|
|
|
|
+ mBinding.ivAction.setOnClickListener {
|
|
|
|
|
+ if (isCollapse) {
|
|
|
|
|
+ mBinding.root.layoutParams = mBinding.root.layoutParams.apply {
|
|
|
|
|
+ height = ctx.resources.getDimensionPixelSize(R.dimen.expandable_tab_expand_height)
|
|
|
|
|
+ }
|
|
|
|
|
+ mBinding.root.requestLayout()
|
|
|
|
|
+
|
|
|
|
|
+ val layoutManager = GridLayoutManager(ctx, 5)
|
|
|
|
|
+ mBinding.rvTab.layoutManager = layoutManager
|
|
|
|
|
+
|
|
|
|
|
+ mBinding.llContainer.orientation = LinearLayout.VERTICAL
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mBinding.root.layoutParams = mBinding.root.layoutParams.apply {
|
|
|
|
|
+ height = ctx.resources.getDimensionPixelSize(R.dimen.expandable_tab_collapse_height)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val layoutManager = LinearLayoutManager(ctx)
|
|
|
|
|
+ layoutManager.orientation = LinearLayoutManager.HORIZONTAL
|
|
|
|
|
+ mBinding.rvTab.layoutManager = layoutManager
|
|
|
|
|
+
|
|
|
|
|
+ mBinding.llContainer.orientation = LinearLayout.HORIZONTAL
|
|
|
|
|
+ }
|
|
|
|
|
+ isCollapse = !isCollapse
|
|
|
|
|
+
|
|
|
|
|
+ mBinding.ivAction.rotation = if (isCollapse) 0f else 180f
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|