zoukankan      html  css  js  c++  java
  • 获取ScrollView ListView的当前位置的百分比

    找不到官方的API,就自己写了一下,下面是自己写的函数 

    --获取滚动层当前位置的百分比
    function GetScrollViewPercent(scrollView)
        if scrollView == nil then return end
        local size = scrollView:getInnerContainerSize()         --内容区大小
        local pos = scrollView:getInnerContainerPosition()      --内容区当前位置
        local listSize = scrollView:getContentSize()            --列表可见区域大小
        
        local persent = 100
        --顶部是100,底部是0,所以用100去减       偏移量只移动左下角,所以最大偏移量=总高度 - 列表可见区域
        if size.height-listSize.height > 0 then
            persent = 100 - math.abs(pos.y/(size.height-listSize.height) *100)
        end
    
        return persent
    end
    

    PS:其他相关,参考来源:http://www.cocoachina.com/bbs/read.php?tid=231462

    我是3.9 依次调用一下代码即在本帧让所有items的位置正确。这个是lua (函数是一样的)的,c++的函数有些事protected的要弄成public。
    listCtro:requestDoLayout();
    listCtro:doLayout();
    listCtro:getInnerContainer():forceDoLayout();

  • 相关阅读:
    [C++]仿java.lang.String的字符串工具类[原]
    SQL基础1创建表、用户
    Linux中gdb 查看core堆栈信息
    Direct3D9基础工具类[原]
    eclipse3.4启动错误
    ndk连接第三方库
    数据库基本概念
    MySQL常见命令
    MySQL启动和停止
    MySQL配置文件
  • 原文地址:https://www.cnblogs.com/mingfuqishi/p/7827267.html
Copyright © 2011-2022 走看看