带动态页码导航的分页

问题描述 投票:0回答:1

enter image description here所以,我想创建图像中显示的视图。

这是我正在开发的项目的用户界面!!

首先我认为我应该使用回收器视图等,但后来我认为逻辑将非常困难!
现在我迷路了

我真的不知道!!

android user-interface android-recyclerview
1个回答
0
投票

所以正如我告诉你的,我想到了具有自定义逻辑的回收器视图! 它起作用了!!

根据要求,我想要大小为 5 的新列表 所以,我有自己的逻辑

fun main() {
    var l: ArrayList<Int?> = arrayListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    newList(l, 5)
    }
   
fun newList(list: ArrayList<Int?>, selected: Int = 1): ArrayList<Int?> 
   {

    var newList: ArrayList<Int?> = arrayListOf()

    if (list.size <= 5) {
        return list
    }
    if (selected == 1 || selected == list.size || list.size - selected == 1) {
        newList = arrayListOf(1, 2, null, list.size - 1, list.size)

    } else if (selected - 1 >= 2) {
        newList = arrayListOf(1, null, selected)
        if (list.size - selected >= 2) {
            newList.add(null)
            newList.add(list.size)
        }

    } else if (selected - 1 == 1) {
        newList = arrayListOf(1, selected, null, list.size - 1, list.size)
    }

    return newList
}
© www.soinside.com 2019 - 2024. All rights reserved.