首页 > 代码库 > 无滚动条GridView少量图片展示
无滚动条GridView少量图片展示
import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.widget.GridView;public class NoScrollGridView extends GridView { private static final String TAG = "NoScrollGridView"; private static final int BLANK_POSITION = -1; private OnTouchBlankPositionListener mTouchBlankPosListener; public NoScrollGridView(Context context) { super(context); } public NoScrollGridView(Context context, AttributeSet attrs) { super(context, attrs); } @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 OnTouchBlankPositionListener { boolean onTouchBlankPosition(); } public void setOnTouchBlankPositionListener(OnTouchBlankPositionListener listener) { mTouchBlankPosListener = listener; } @Override public boolean onTouchEvent(MotionEvent event) { if (mTouchBlankPosListener != null) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn‘t respond to them. return isClickable() || isLongClickable(); } if (event.getActionMasked() == MotionEvent.ACTION_UP) { final int motionPosition = pointToPosition((int) event.getX(), (int) event.getY()); if (motionPosition == BLANK_POSITION) { return mTouchBlankPosListener.onTouchBlankPosition(); } } } return super.onTouchEvent(event); }}
无滚动条GridView少量图片展示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。