您的位置:首页 > 其它

自定义可以设置最大高度的ListView

2018-03-27 00:13 399 查看
原文地址:http://blog.csdn.net/x1051340616/article/details/53036910

public class MaxListView extends ListView {
/**
* listview高度
*/
private int listViewHeight;

public int getListViewHeight() {
return listViewHeight;
}

public void setListViewHeight(int listViewHeight) {
this.listViewHeight = listViewHeight;
}

public MaxListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

public MaxListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}

public MaxListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
if (listViewHeight > -1) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(listViewHeight,
MeasureSpec.AT_MOST);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

}

lv_kechengbiaoqian.setListViewHeight(500);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  自定义 ListView