设置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);
}
}
}