扁平的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 = 0val lists = mutableListOf<MutableList<String>>()for (i in array.indices step STEP) {val temp = mutableListOf<String>()for (j in 0 until STEP) {k = i + jif (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
?