设置listview高度包裹内容

来源:互联网 发布:数据库是什么文件 编辑:程序博客网 时间:2024/04/19 15:07

设置listview高度包裹内容,可以在布局文件设置height为wrap_content

public class ExpandListView extends ListView{    public ExpandListView(Context context,AttributeSet attrs){        super(context,attrs);    }    private int maxHeight = 0;    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){        int expandSepc = 0;        if(maxHeight > 0){            expandSepc = maxHeight;        }else{            expandSepc = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);            super.onMeasure(widthMeasureSpec,expandSepc);        }    }}
0 0