Android ScrollView中嵌套ExpandableListView,item不显示的问题

在项目中,发现当需要用ScrollView嵌套ExpandableListView时,无论ExpandableListView的width设置为match_parent还是wrap_content,其item均只显示group的第一个,其他都不显示,点开group第一行,里面的child数据也不显示。网上查阅后发现,需要重新设置ExpandableListView的高度,代码如下:
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的一些属性android:divider="@null" 表示group item之间无分割线;android:groupIndicator="@null"表示group item显示展开或收缩的图标消失。

猜你喜欢

转载自blog.csdn.net/androidforwell/article/details/65635542
今日推荐