现在的位置: 首页 > 综合 > 正文

Listview 高度调整

2013年05月17日 ⁄ 综合 ⁄ 共 869字 ⁄ 字号 评论关闭

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

 }
}

抱歉!评论已关闭.