最近碰到需求需要实现GridView空白处的点击事件,记录一下:
这次也需要我们定义一个类去继承GridView,先上代码在解释
public class UnscrollableGridView extends GridView {
private OnTouchBlankListener OnTouchBlankListener;
public UnscrollableGridView(Context context) {
super(context);
}
public UnscrollableGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public UnscrollableGridView(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);
}
//定义回调接口
public interface OnTouchBlankListener {