LayaAir之List
admin
2023-02-16 20:20:03
0次

注意 : 引擎选用的是LayaAir 2.0.0.bate4
一,前言 : 在List中加入ScrollBar是很简单的 . 如下图:
LayaAir之List
但是 , 这些滑动条不太简洁 , 可能入不了你我的法眼.
①,传统滑动条分4部分组成
LayaAir之List
我们放入Ui , 看看效果:
LayaAir之List
乘上 , 如想实现简洁版的滑动条(其实只是需要一些简单的功能). 可以完全使用Slider来做.如下 :
LayaAir之List

二,关联List和Slider
List的一般基础设置:

        this.con_list.itemRender = BallSkinRender;
        this.con_list.array = null;
        this.con_list.vScrollBarSkin = "";
        this.con_list.scrollBar.elasticBackTime = 500;
        this.con_list.scrollBar.elasticDistance = 200;
        this.con_list.repeatX = 4;
        this.con_list.spaceX = 10;
        this.con_list.spaceY = 10;
        this.con_list.scrollBar.isVertical = true;
        this.con_list.scrollBar.setScroll( 0 , 100, 0 );

        this.con_list.selectHandler = Laya.Handler.create(this , this._list_select , null , false);
        this.con_list.scrollBar.changeHandler = Laya.Handler.create( this , this._scroll_Change , null , false );

注解 :
① : 设置 this.con_list.vScrollBarSkin = ""; 才能设置回弹 , 进度等信息 . 比如 :this.con_list.scrollBar.changeHandler = Laya.Handler.create( this , this._scroll_Change , null , false );
我们可以侦听到进度的信息.

② : this.con_list.scrollBar.setScroll( 0 , 100, 0 ); 参数 : 1 , 最小值 ; 2 , 最大值 ; 3 , 当前值

核心关联:

    /**
     * 选择元素
     * @param {number} $index 从0开始
     * @private
     */
    private _list_select( $index : number ) : void{
        console.log(`AAACCC : ${$index}`);
    }

    private _scroll_Change( $value : number ) : void{
        if( $value <= 0 ){
            this.vs_bar.value = 0;
        }else if( $value >= this.con_list.scrollBar.max ){
            this.vs_bar.value = 100;
        }else{
            this.vs_bar.value = ( ($value * 1.0) / this.con_list.scrollBar.max ) * 100;
        }
    }

注解 : ① : vs_bar 即 Slider
② : _scroll_Change方法实现了关联.(是Slider滑块位置准确反映List拖动的进度).






补充 , 关于LayaAir1.0的list编程的方案及注意点

①,为list绑定一个渲染的方法 ( $cell : CellRender , $index : number ) => void
①-1 , $cell : 渲染的cell单元
①-2 , $index : 渲染cell的序列 , 从0开始
①-3 , 具体绑定代码如下:

this.con_list.renderHandler = new Laya.Handler( this , this.updateItem );

②,显示绑定的方法

        public updateItem( $cell :  BallSkinRender , $index : number ) : void{
            $cell.~~DataSource~~ = $cell.dataSource;
        }

注意 : $cell.dataSource的数据是通过list.array里面自动获取的.在BallSkinRender中,实现DataSource的set方法就行.另外 , 不需要list.refresh方法
在LayaAir2.0中 , 需要在Render类中实现dataSource的set方法(注意大小写),需要用到list.refresh方法.不需要使用list.renderHandler绑定渲染方法.

使用 : this.con_list.changeItem( $i , this.con_list.array[$i] ); 更新list中的第几个(从0开始)Cell的值.

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...