当我们用ScrollView嵌套listview和GridVIew的时候,经常会遇到listview中的内容不能全部显示问题,想要解决这个问题也很简单,只要我们重写listview和gridview这俩个空间就可以了,具体步骤和方法如下。
1自定义lisetview控件
package com.yhkj.jskf.southwestcementmt_salesman.utils;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class MY ListView extends ListView {
public AllListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, mExpandSpec);
}
}
package com.yhkj.jskf.southwestcementmt_salesman.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;
/**
* 自定义GridView控件
* @Type: MyGridView 让GridView可以做ScrollView的子控件,但尺寸不会减小
*/
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
2在xml中引用自定义的控件
<com.yhkj.jskf.southwestcementmt_salesman.utils.AllListView
android:divider="#cccccc"
android:id="@+id/lv"
android:cacheColorHint="#00000000"
android:dividerHeight="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll_allcontent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none" >
</com.yhkj.jskf.southwestcementmt_salesman.utils.AllListView>
<com.yhkj.jskf.southwestcementmt_salesman.widget.MyGridView
android:id="@+id/gvNetworkInformation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:verticalSpacing="10dp" />
3在activity里引用这两个控件就ok了,
以上问题就解决了