ExpandableListView中item的定位问题
来源:互联网 发布:说话技巧 叶名琛 知乎 编辑:程序博客网 时间:2024/06/07 03:29
ExpandableListView中position一般有两个常见的参数 , 即groupPosition和childPosition . 但是当我们想要将ExpandableListView定位到某一个固定的item时 , 其提供的setSelectionFromTop(position,top)方法中的position应该是哪个参数呢 ? 其实 , groupPosition和childPosition 都不是.
我们先来了解一下ExpandableListView中position的概念 , 其有4个相关的position概念:
1.groupPosition
2.childPosition
3. Packed position:
包含了类型信息(group, child, or null for headers/footers),Group position,Child position信息的position
4.FlatListPosition
listview的原始position(包括childPosition 和 groupPosition)
转换公式:
1.FlatList position -> Packed position -> ExpandableList Group/Child positions
// a. Flat list position -> Packed position
long packedPosition = getExpandableListPosition(flatListPosition);
// b. Unpack packed position type
int positionType = getPackedPositionType(packedPosition);
//c. 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);
//从groupPos和childPos获得flatListPosition
int flatListPosition= mCardListView.getFlatListPosition(groupPos, childPos);
public int getFlatListPosition(int groupPos, int childPos) {
long packetPosition = ExpandableListView.getPackedPositionForChild(groupPos, childPos);
return mRefreshableView.getFlatListPosition(packetPosition);
}
**好了,知道了ExpandableListView的概念,我们就可以使用listview提供的setSelectionFromTop(position,top)方法了!
只要把计算出flatListPosition代入setSelectionFromTop(position,top)就可以了!**
(ps:1.top指左顶点坐标,可以通过Listview.getChildAt(index).getTop()获得
2.Listview.getChildAt(index),中index指的是屏幕可见范围内的第index项,而不是listview的第index项)
- ExpandableListView中item的定位问题
- Android ScrollView中嵌套ExpandableListView,item不显示的问题
- ExpandableListView点击最后一个child item不回调onChildClick()的问题
- 修改ExpandableListView中父Item的箭头图标
- ExpandableListView中ListView无法使用Item的监听事件
- ListView中item定位
- ExpandableListview中 解决ImageButton冲突的问题。
- ExpandableListView使用中遇到的各种问题
- Android:解决ExpandableListView中添加button后item项点击事件问题
- Android:解决ExpandableListView中添加button后item项点击事件问题
- expandablelistview子item的按钮怎么获取
- expandablelistview 动态添加不同的子item。
- expandablelistview子item的按钮怎么获取
- ExpandableListView去掉item分割线的方法
- Android--ExpandableListView的item点击监听事件
- 关于ListView中Item动态加载的例子(android)(ExpandAbleListView)
- ExpandableListView的注意问题
- ExpandableListView的注意问题
- 【java】嵌套矩形
- jQuery最后案例
- hdu2065 “红色病毒” 指数型母函数
- Java回炉重造(一)Socket的客户端和服务端通信
- JS字符串对象
- ExpandableListView中item的定位问题
- 数据结构—链表-链式存储
- 初学web前端-20170424
- Android Studio 常用快捷键整理
- 无法插入中文修改mysql表的编码格式
- zookeeper中启动出现闪退
- tomcat启动报错
- java基础学习(11)字符串
- 区间第k大的数 划分树模板