-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlidingBlockActionActivity.kt
76 lines (66 loc) · 2.7 KB
/
SlidingBlockActionActivity.kt
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.zhangjian.samp.slidingblock
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zhangjian.samp.ButtonRouter
import com.zhangjian.samp.MenuListAdapter
import com.zhangjian.samp.R
import com.zhangjian.samp.getRandColorInt
import com.zhangjian.uikit.tab.SlidingBlockTabView
/**
* Created zhangjian on 2021/9/22(10:31) in project UiKit.
*/
class SlidingBlockActionActivity : FragmentActivity() {
var curRecycleViewIndex = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sliding_block_action)
val recycleView: RecyclerView = findViewById(R.id.rvContent)
val tabView: SlidingBlockTabView = findViewById(R.id.slidingBlock)
val titles = mutableListOf<String>()
titles.apply {
add("GROUP1")
add("GROUP2")
add("GROUP3")
add("GROUP4")
add("GROUP5")
}
val linearLayoutManager = LinearLayoutManager(this@SlidingBlockActionActivity)
recycleView.apply {
val buttonRouters: MutableList<ButtonRouter> = mutableListOf()
buttonRouters.apply {
for (title in titles) {
val textBuilder = StringBuilder(title)
for (i in 0 until 30) {
textBuilder.append("\n")
}
add(ButtonRouter(textBuilder.toString()){
it.setBackgroundColor(getRandColorInt())
it.gravity = Gravity.CENTER
it.setTextColor(Color.WHITE)
})
}
}
layoutManager = linearLayoutManager
adapter = MenuListAdapter(buttonRouters)
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val firstVisibleIndex =
linearLayoutManager.findFirstVisibleItemPosition()
if (firstVisibleIndex != curRecycleViewIndex) {
tabView.activeScrollToIndex(firstVisibleIndex)
curRecycleViewIndex = firstVisibleIndex
}
}
})
}
tabView.bindTabTitles(titles) {
linearLayoutManager.scrollToPositionWithOffset(it, 0)
}
}
}