自定义listView在屏幕里显示的高度,在自定义有列表的Dialog时候用的着,不然列表会被拉得很长,影响感观!
public class MyListView extends ListView {
/**自定义 listview高度 */
private int listViewHeight = 460;
public int getListViewHeight() {
return listViewHeight;
}
public void setListViewHeight(int listViewHeight) {
this.listViewHeight = listViewHeight;
}
public MyListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyListView(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);
}
//
// @Override
// public void setCacheColorHint(int color) {
//
// super.setCacheColorHint(R.color.list_cache);//点击列表项时候的背景色
// }
}