【安卓】ExpandableListView中的position
来源:互联网 发布:北京好的编程培训机构 编辑:程序博客网 时间:2024/06/04 23:18
原文地址:http://m.blog.csdn.net/blog/w7822938/38926511(有删改)
------------------------------
ExpandableListView的position一般只需要知道groupPosition&childPosition就足够了,
但是当遇到要精确记录,移动到ExpandableListView的某个item上,listview提供的setSelectionFromTop(position,top)似乎就'失效'了..
其实不然,只是你传入的position并不是ListView所认识的position罢了;
ExpandableListView中有4个position概念:
1.Flat list position:
listview的原始position(包括child,group)
2.Packed position:
包含了类型信息(group, child, or null for headers/footers),Group position,Child position信息的position
3.Group position:
4.Child position:
转换公式:
1.FlatList position -> Packed position -> ExpandableList Group/Child positions
// 1. Flat list position -> Packed position
long packedPosition = getExpandableListPosition(flatListPosition);
// 2. Unpack packed position type
int positionType = getPackedPositionType(packedPosition);
// 3. Unpack position values based on positionType
// 如果positionType不是空类型,就是Group,或者Child
if( positionType != PACKED_POSITION_TYPE_NULL ){
// (Child类型时也有Group信息)
groupPosition = getPackedPositionGroup(packedPosition);
// 如果是child类型,则取出childPosition
if(positionType == PACKED_POSITION_TYPE_CHILD){
childPosition = getPackedPositionChild(packedPosition);
}
}else{
Log.d("FooLabel", "positionType was NULL - header/footer?");
}
2.ExpandableList Group/Child positions ->Packed position ->FlatList position
// 要从groupPosition或者childPosition转换到flatPosition就简单了
// 先由groupPosition获得packedPosition
long packedPosition = getPackedPositionForGroup(groupPosition); //获得childPosition的packedPosition则使用getPackedPositionForChild()方法
// 再由packedPosition获得flatListPosition
int flatListPosition= getFlatListPosition(packedPosition);
好了,知道了ExpandableListView的概念,我们就可以使用listview提供的setSelectionFromTop(position,top)方法了!
只要把计算出flatListPosition代入setSelectionFromTop(position,top)就可以了!
(ps:1.top指左顶点坐标,可以通过Listview.getChildAt(index).getTop()获得
2.Listview.getChildAt(index),中index指的是屏幕可见范围内的第index项,而不是listview的第index项)
0 0
- 【安卓】ExpandableListView中的position
- ExpandableListView中的position
- 安卓ExpandableListView实例
- 安卓ExpandableListView的用法
- 安卓ExpandableListView.getChildAt(arg0);
- 安卓二级列表 ExpandableListView
- ExpandableListView的position
- 【安卓笔记】ExpandableListView的使用
- 基于安卓ExpandableListView的简单实现
- 安卓 ExpandableListView的使用详解
- 安卓ExpandableListView的简单使用
- 安卓ExpandableListView实现多组列表,类似于QQ分组
- ExpandableListView安卓开发可扩展的listview
- 安卓开发ExpandableListView并且子视图为gridview
- 安卓自定义控件之带有折叠动画的ExpandableListView
- android ExpandableListView position - packPostion - group/childposition
- Android ExpandableListView 长按事件 position问题
- android中的ExpandableListView使用
- Jquery easyui总结
- iOS delegate 的使用
- 远程启动Qtp/UFT开始测试
- thinkphp模板大小写问题
- 【未解决】html中的a标签id与class冲突
- 【安卓】ExpandableListView中的position
- 封装Android文件基本操作方法
- andorid serviceconnection
- Python *与** 参数问题
- STM32软件复位(基于库文件V3.5)
- linux uevent分析
- django log问题
- linux如何运行.bin文件
- Could not find file 'Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0' 问题