原文地址:http://blog.youkuaiyun.com/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来设置固定高度的方法,并提供了具体的Java代码实现。通过对ListView的高度进行控制,可以更好地适配布局需求。
662

被折叠的 条评论
为什么被折叠?



