//创建一个类继承GridView 必须重写前三个方法 和onMeasure方法
public class MyG extends GridView {
public MyG(Context context) {
super(context);
}
super(context);
}
public MyG(Context context, AttributeSet attrs) {
super(context, attrs);
}
super(context, attrs);
}
public MyG(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int newHight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHight);
}
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int newHight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHight);
}
}
//布局调用
<zhanghaijiao.bawei.com.week2_demo.MyGridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gv"
android:numColumns="3"></zhanghaijiao.bawei.com.week2_demo.MyGridView>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gv"
android:numColumns="3"></zhanghaijiao.bawei.com.week2_demo.MyGridView>