其他分享
首页 > 其他分享> > CoordinatorLayout+NestedScrollView+ExpandableListView滚动到ExpandableListView的指定位置

CoordinatorLayout+NestedScrollView+ExpandableListView滚动到ExpandableListView的指定位置

作者:互联网

appBarLayout.setExpanded(false, true);//先缩起AppBarLayout
//然后滚动NestedScrollView
scroll.post(new Runnable() {
@Override
public void run() {
scroll1(expandableListView, finalI, finalJ);
}
});
 public void scroll1(ExpandableListView expandableListView,int groupIndex, int childIndex) {
int totalHeight = 0;
int position = 0;
if(groupIndex==0)
{

View group = expandableListView.getExpandableListAdapter().getGroupView(0, true, null, expandableListView);
//测量高度,这里把子item高度和父item高度视为一样高,不一样高的需要重新测量child的高度
group.measure(0, 0);
totalHeight += group.getMeasuredHeight() ;
}
else
{
for (int i = 0; i < groupIndex; i++) {
position++;
View group = expandableListView.getExpandableListAdapter().getGroupView(i, true, null, expandableListView);
//测量高度
                group.measure(0, 0);
totalHeight += group.getMeasuredHeight() ;
if (expandableListView.isGroupExpanded(i)){
position = position + expandableListView.getExpandableListAdapter().getChildrenCount(i);
}
}
}
position++;
position = position + childIndex;

scroll.smoothScrollTo(0, position*totalHeight);


}
参考https://stackoverflow.com/questions/53474588/scrolltoposition-smoothscrolltoposition-for-recyclerview-under-a-nestedscrollvi
https://blog.csdn.net/weixin_39694016/article/details/117679934


标签:group,ExpandableListView,int,NestedScrollView,groupIndex,expandableListView,Coor
来源: https://www.cnblogs.com/kinoyo/p/15241189.html