废话不多说,上demo地址
先上效果图吧
博主写的已经非常详细了,根据需求又进行了一些调整,主要是去除了标题栏,然后对与右侧最后一个item内容太少时,左侧依然可以定位到最后一个item
思路就是对右侧的最后一个item进行高度测量,然后添加一个与右侧高度差一致的footerView,来看下代码吧
/**
* 计算高度并添加footer
*/
private void addFooter(){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int menuHeight = lvMenu.getHeight();// 左侧菜单栏高度
View view = privilegeRightAdapter.getView(homeList.size() -1,lvPrivilege.getChildAt(homeList.size() -1),lvPrivilege);
view.measure(0,0);
int lastItemHeight = view.getMeasuredHeight();// 右侧最后一个item的高度
int footerHeight = (menuHeight - lastItemHeight) > 58 ? menuHeight - lastItemHeight - DisplayUtil.dip2px(mActivity,8): DisplayUtil.dip2px(mActivity,50);// 设置footer的高度,减去的8为item的marginTop
if (lvPrivilege.getFooterViewsCount() == 0) {
View bottomView = mActivity.getLayoutInflater().inflate(R.layout.privilege_footer_view, null);
bottomView.setMinimumHeight(footerHeight);
lvPrivilege.addFooterView(bottomView);
}
}
}, 500);
}