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的值.

相关内容

热门资讯

河北一演唱会音响“翻车”,人声... 近日,来自北京的庞女士向都市现场记者反映,她7月11日在河北唐山观看“青春超燃巨星演唱会”时遭遇了极...
尺素金声|中国经济“失速论”站... 一季度GDP同比增长5.0%、二季度增长4.3%、上半年增长4.7%,2026年中国经济半年报发布后...
NVIDIA最深的护城河要凉!... 7月24日消息,AMD在Advancing AI预简报会上表示,CUDA已不再是外界想象中的那条护城...
廖杰远:三大智能体协同闭环,A... 中国日报网7月24日电 7月22日,在2026年世界互联网大会数字丝路发展论坛数智健康分论坛上,微医...
AI时代构筑超级底座 维谛技术... 文/本报记者 当前,人工智能产业竞争持续向产业链上游延伸,算力竞争早已不再局限于计算芯片性能比拼。具...
刚签核协议不到24小时,美国突... 美国东部时间7月22日下午,美国宣布与沙特阿拉伯签署了一项民用核能协议。据美国有线电视新闻网(CNN...
中国信通院牵头,数据编织国际标... IT之家 7 月 24 日消息,中国信通院今日发文称,国际电信联盟第 21 研究组(ITU-T SG...
国内首颗商业空间碎片监测卫星发... 【国内首颗商业空间碎片监测卫星发射成功】《科创板日报》24日讯,7月24日上午,中科宇航力箭一号运载...
邓煜,诗人,数学家,老二次元 来源 视觉中国菲尔兹奖的通知邮件抵达时,普林斯顿大学数学博士、芝加哥大学数学系教授邓煜正在看一本恋爱...
安全生产许可证状态不是“有效”... 工程公司的安全生产许可证在官方系统显示为“其他”状态,有一栏则显示“整改”,却成为高标准农田项目的第...