无滚动条GridView少量图片展示_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 无滚动条GridView少量图片展示

无滚动条GridView少量图片展示

 2014/10/28 11:37:05  祁连山  程序员俱乐部  我要评论(0)
  • 摘要:importandroid.content.Context;importandroid.util.AttributeSet;importandroid.util.Log;importandroid.view.MotionEvent;importandroid.widget.GridView;publicclassNoScrollGridViewextendsGridView{privatestaticfinalStringTAG="NoScrollGridView"
  • 标签:
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);
    }
}

 

上一篇: Windows Phone自带的语音识别 下一篇: 没有下一篇了!
  • 相关文章
发表评论
用户名: 匿名