网上也找到几个方法解决但是感觉最好用最简单的还是以下的自定义ListView好用
创建自定义View继承ListView实现三个构造方法,重写onMeasure(int widthMeasureSpec, int heightMeasureSpec)方法
public class MyListview extends ListView {
public MyListview(Context context) {
super(context);
}
public MyListview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListview(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);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
之后就是在布局中引用该自定义ListView,添加适配器即可
<com.text.view.MyListview
android:id="@+id/home_goods_lv_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false" />