Listview 高度调整

package com.yek.android.gap.views;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class NoScrollListView extends ListView {

 public NoScrollListView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }
 public NoScrollListView(Context context) {
  super(context);
 }
 @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);

 }
}

posted @ 2012-09-20 17:46  疯子FK  阅读(468)  评论(0编辑  收藏  举报