首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

ListView整合高度

2012-08-30 
ListView调整高度listView 有时候项目太少占用空间太大,如何能够自动控制自适用大小package com.customcon

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);?
? ? }?
}?

热点排行