ScrollView中嵌套ExpandableListView

本文介绍了一种解决ScrollView中嵌套使用ExpandableListView时高度限制的问题的方法。通过创建一个自定义的NestedExpandaleListView类并调整其测量过程,使得在ScrollView内部的ExpandableListView能够正确展示所有内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为了让SrollView中嵌套ExpandableListView,我们就得改ListView的高度,所以写一个类继承于ExpandableListview:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ExpandableListView;


/**
 * Created by liang on 2016/8/21.
 */
public class NestedExpandaleListView extends ExpandableListView {
    public NestedExpandaleListView(Context context,AttributeSet attrs){
        super(context,attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,

                MeasureSpec.AT_MOST);

        //将重新计算的高度传递回去
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

这样大概就可以了,以后用到的ExpandableListView就改为NestedExpandaleListView(包括xml文件,activity中用到的地方)就可以了。

参考资料:http://blog.youkuaiyun.com/swust_chenpeng/article/details/17413955

转载于:https://www.cnblogs.com/Liang-Blog/p/5794106.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值