Android触屏事件(二、事件分发)

来源:互联网 发布:python tkinter 滚动条 编辑:程序博客网 时间:2024/05/27 20:51

在这里,我们了解到把实现GestureDetector中接口的自定义类放到 onTouchEvent方法中更加合适。

package android.view.View;

    /**     * Pass the touch screen motion event down to the target view, or this view if it is the target.     *     * @param event The motion event to be dispatched.     * @return True if the event was handled by the view, false otherwise.     */    public boolean dispatchTouchEvent(MotionEvent event) {……}

package android.view.Window;

        /**         * Called to process touch screen events.  At the very least your implementation must call         * {@link android.view.Window#superDispatchTouchEvent} to do the         * standard touch screen processing.         *         * @param event The touch screen event.         *         * @return boolean Return true if this event was consumed.         */        public boolean dispatchTouchEvent(MotionEvent event);

android.view.ViewGroup

/**Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.*/public boolean onInterceptTouchEvent(MotionEvent ev){……};

package android.app.Activity;

    /**     * Called when a touch screen event was not handled by any of the views under it.  This is most useful to process touch events that happen outside of your window bounds, where there is no view to receive it.     *     * @param event The touch screen event being processed.     *     * @return Return true if you have consumed the event, false if you haven't.     * The default implementation always returns false.     */    public boolean onTouchEvent(MotionEvent event) {……}

package android.view.View;

    /**     * Implement this method to handle touch screen motion events.     * <p>     * If this method is used to detect click actions, it is recommended that     * the actions be performed by implementing and calling     * {@link #performClick()}. This will ensure consistent system behavior,     * including:     * <ul>     * <li>obeying click sound preferences     * <li>dispatching OnClickListener calls     * <li>handling {@link AccessibilityNodeInfo#ACTION_CLICK ACTION_CLICK} when     * accessibility features are enabled     * </ul>     *     * @param event The motion event.     * @return True if the event was handled, false otherwise.     */    public boolean onTouchEvent(MotionEvent event) {……}