扁平的MutableList元素每隔若干元素一组装入新MutableList,Kotlin
fun main(args: Array<String>) {
val array = arrayOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
val STEP = 3 //3个元素一组
var k = 0
val lists = mutableListOf<MutableList<String>>()
for (i in array.indices step STEP) {
val temp = mutableListOf<String>()
for (j in 0 until STEP) {
k = i + j
if (k >= array.size) {
break
}
temp.add(array[k])
}
lists.add(temp)
}
lists.forEachIndexed { index, s ->
println(s)
}
}
[a, b, c]
[d, e, f]
[g, h, i]
[j]
Android Glide自定义AppCompatImageView切分成若干小格子,每个小格子onDraw绘制Bitmap,Kotlin(1)-CSDN博客文章浏览阅读386次,点赞5次,收藏6次。垂直方向的RecyclerView,每行一个AppCompatImageView,每个AppCompatImageView被均匀切割成n个小格子, 每个小格子通过Glide加载出来Bitmap,然后onDraw绘制整行。//读取所有图片!//路径 uri//图片名称//图片大小= null,const val ROW_SIZE = 16 //一行多少个bitmap。https://blog.csdn.net/zhangphil/article/details/134519527
给定长度值length,把列表切分成每段长度为length的N段列表,Kotlin_zhangphil的博客-CSDN博客文章浏览阅读652次。总长度:22 随机生成每段长度:4 算出段数:6。https://blog.csdn.net/zhangphil/article/details/131999459