ListView.getCount() 与 ListView.getChildCount()
2009-11-30 15:44
260 查看
ListView.getCount()(实际上是 AdapterView.getCount()) 返回的是其 Adapter.getCount() 返回的值。也就是“所包含的 Item 总个数”。
ListView.getChildCount()(ViewGroup.getChildCount) 返回的是显示层面上的“所包含的子 View 个数”。
二者有什么不同?当 ListView 中的 Item 比较少无需滚动即可全部显示时,二者是等价的;当 Item 个数较多需要滚动才能浏览全部的话, getChildCount() < getCount() 其中 getChildCount() 返回的是当前可见的 Item 个数。
其实 Android framework 的这一设计并不难理解:当一些 Item 当前不显示的时候为什么还要保留它们的 View 呢?移动设备的资源有限,“能省则省”嘛。
ListView.getChildCount()(ViewGroup.getChildCount) 返回的是显示层面上的“所包含的子 View 个数”。
二者有什么不同?当 ListView 中的 Item 比较少无需滚动即可全部显示时,二者是等价的;当 Item 个数较多需要滚动才能浏览全部的话, getChildCount() < getCount() 其中 getChildCount() 返回的是当前可见的 Item 个数。
其实 Android framework 的这一设计并不难理解:当一些 Item 当前不显示的时候为什么还要保留它们的 View 呢?移动设备的资源有限,“能省则省”嘛。
相关文章推荐
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- Android中ListView.getCount()与ListView.getChildCount()区别
- Android mListView.getChildCount()和mAdapter.getCount()的区别
- android开发之ListView.getCount()与ListView.getChildCount()区别
- ListView.getCount() 与 ListView.getChildCount()
- ListView.getCount()与ListView.getChildCount() OnScrollListener()
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- ListView.getCount() 与 ListView.getChildCount()
- ListView.getCount() 与 ListView.getChildCount()
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- Android中ListView.getCount()与ListView.getChildCount()区别
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别
- ListView.getCount()与ListView.getChildCount()区别
- android-细节问题-ListView 在 setAdapter() 后 getChildCount() 值为0
- gridView getCount与getChildCount
- 菜鸟学android---为什么listView.getChildCount()值为0
- ListView.getChildCount() 详解