天天看點

wheelView 的單擊事件(轉載他人代碼)

wheelview 網絡版很好,根據實際需要修改一下,謝謝寫出代碼的前輩們

@Override

        public boolean onSingleTapConfirmed(MotionEvent e) {

            int touchY=(int)e.getY();

            int center=DEF_VISIBLE_ITEMS/2;

            Rect bounds = new Rect();

            itemsLayout.getLineBounds(center, bounds);

           int line = center;

            if (touchY < bounds.top) {

                line--;

                while (line >= 0) {

                    itemsLayout.getLineBounds(line, bounds);

                    if (touchY >= bounds.top && touchY <= bounds.bottom) {

                        break;

                    }

                    line--;

                }

            } else if (touchY > bounds.bottom) {

                line++;

                while (line <= DEF_VISIBLE_ITEMS ) {

                    itemsLayout.getLineBounds(line, bounds);

                    if (touchY >= bounds.top && touchY <= bounds.bottom) {

                        break;

                    }

                    line++;

                }

            }

            scroller.startScroll(0, lastScrollY, 0, (line - center)*getItemHeight()+scrollingOffset);

            setNextMessage(MESSAGE_SCROLL);

            return true;

        }

繼續閱讀