Android仿京东分类页 左右联动ListView

废话不多说,上demo地址

转载原地址:https://www.jianshu.com/p/41b4b749ac28

先上效果图吧

在这里插入图片描述

博主写的已经非常详细了,根据需求又进行了一些调整,主要是去除了标题栏,然后对与右侧最后一个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);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值