自定义listview 为什么不能动态设置高度
public class BulkListview extends ListView {
public BulkListview (Context context) {
super(context);
}
public BulkListview (Context context, AttributeSet attrs) {
super(context, attrs);
}
public BulkListview (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
Log.i("onMeasure","onMeasure expandSpec="+expandSpec);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
以上是自定义listview
下面是调用方式,设置高度没有效果height和height2数值是一样的
int width = list_other_list.getWidth();
int height = list_other_list.getHeight();
Log.i("Log: ", "-----------1>"+width + " | " + height);
ViewGroup.LayoutParams params = list_other_list.getLayoutParams();
params.height =800;
params.width =width;
list_other_list.setLayoutParams(params);
int width2 = list_other_list.getWidth();
int height2 = list_other_list.getHeight();
Log.i("Log: ", "-----------2>"+width2 + " | " + height2);