ListView调整高度
listView 有时候项目太少占用空间太大,如何能够自动控制
自适用大小
package com.customcontrols;?
public class NoScrollListView extends ListView?
{?
? ? @Override?
? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)?
? ? {?
? ? ? ? super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0) );?
?
? ? ? ? // here I assume that height's being calculated for one-child only, seen it in ListView's source which is actually a bad idea?
? ? ? ? int childHeight = getMeasuredHeight() - (getListPaddingTop() + getListPaddingBottom() + ?getVerticalFadingEdgeLength() * 2);?
?
? ? ? ? int fullHeight = getListPaddingTop() + getListPaddingBottom() + childHeight*(getCount());?
?
? ? ? ? setMeasuredDimension(getMeasuredWidth(), fullHeight);?
? ? }?
}?