android 事件分发 view和viewgroup

事件分发涉及到的事件

dispatchTouchEvent,onInterceptTouchEvent,onTouchEvent

监听事件

setOnTouchListener,setOnClickListener,setOnLongClickListener

事件分发log

viewgroup
正常流程dispatchTouchEvent(父)->onInterceptTouchEvent(父)->dispatchTouchEvent(子)->onTouchEvent(子)
1、linearLayout dispatchTouchEvent  super.dispatchTouchEvent(ev) onInterceptTouchEvent super.onInterceptTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
TextView dispatchTouchEvent super.dispatchTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
05-04 18:05:01.591 22765-22765/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:05:01.601 22765-22765/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_DOWN


05-04 18:05:01.601 22765-22765/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-04 18:05:01.601 22765-22765/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN


05-04 18:05:01.611 22765-22765/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:05:01.611 22765-22765/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_MOVE


05-04 18:05:01.611 22765-22765/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-04 18:05:01.611 22765-22765/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE




05-04 18:05:01.641 22765-22765/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_UP
05-04 18:05:01.641 22765-22765/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_UP
05-04 18:05:01.641 22765-22765/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-04 18:05:01.641 22765-22765/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP

2、linearLayout dispatchTouchEvent  true  onInterceptTouchEvent super.onInterceptTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
TextView dispatchTouchEvent super.dispatchTouchEvent(ev) onTouchEvent super.onTouchEvent(event) 
05-04 18:09:55.981 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:09:56.001 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:09:56.011 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:09:56.031 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:09:56.041 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:09:56.041 28865-28865/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_UP


3、linearLayout dispatchTouchEvent  super.dispatchTouchEvent(ev) onInterceptTouchEvent true onTouchEvent super.onTouchEvent(event)
TextView dispatchTouchEvent super.dispatchTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
05-04 18:11:00.111 30110-30110/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:11:00.121 30110-30110/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_DOWN
05-04 18:11:00.121 30110-30110/com.example.eventdispatch I/XQLOG: ll_onTouchEvent_ACTION_DOWN




4、linearLayout dispatchTouchEvent  true  onInterceptTouchEvent super.onInterceptTouchEvent(ev) onTouchEvent true
TextView dispatchTouchEvent super.dispatchTouchEvent(ev) onTouchEvent super.onTouchEvent(event) 


05-04 18:18:06.861 6477-6477/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:18:06.861 6477-6477/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_DOWN
05-04 18:18:06.861 6477-6477/com.example.eventdispatch I/XQLOG: ll_onTouchEvent_ACTION_DOWN
05-04 18:18:06.881 6477-6477/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:18:06.881 6477-6477/com.example.eventdispatch I/XQLOG: ll_onTouchEvent_ACTION_MOVE
05-04 18:18:06.901 6477-6477/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:18:06.901 6477-6477/com.example.eventdispatch I/XQLOG: ll_onTouchEvent_ACTION_MOVE
05-04 18:18:06.901 6477-6477/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_UP
05-04 18:18:06.901 6477-6477/com.example.eventdispatch I/XQLOG: ll_onTouchEvent_ACTION_UP








5、linearLayout dispatchTouchEvent  super.dispatchTouchEvent(ev) onInterceptTouchEvent super.onInterceptTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
TextView dispatchTouchEvent true onTouchEvent super.onTouchEvent(event)
05-04 18:12:52.271 32029-32029/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:12:52.271 32029-32029/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_DOWN
05-04 18:12:52.271 32029-32029/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-04 18:12:52.301 32029-32029/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_MOVE
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_UP
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_UP
05-04 18:12:52.311 32029-32029/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP

6、linearLayout dispatchTouchEvent  super.dispatchTouchEvent(ev) onInterceptTouchEvent super.onInterceptTouchEvent(ev) onTouchEvent super.onTouchEvent(event)
TextView dispatchTouchEvent super.dispatchTouchEvent(ev) onTouchEvent true
05-04 18:14:18.521 2022-2022/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_DOWN
05-04 18:14:18.521 2022-2022/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_DOWN
05-04 18:14:18.531 2022-2022/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-04 18:14:18.531 2022-2022/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_MOVE
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_MOVE
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: ll_dispatchTouchEvent_ACTION_UP
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: ll_onInterceptTouchEvent_ACTION_UP
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-04 18:14:18.641 2022-2022/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP





view  
正常流程dispatchTouchEvent->OnTouchListener->onTouchEvent->setOnLongClickListener->setOnClickListener
·、OnTouchListener false  setOnLongClickListener false   onTouchEvent super.onTouchEvent(event)  dispatchTouchEvent super.dispatchTouchEvent(ev)
短按
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-05 09:38:49.181 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:38:49.421 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:38:49.421 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: setOnClickListener
长按
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:38:49.171 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-05 09:38:49.181 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:38:49.421 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:38:49.421 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:38:49.431 32525-32525/com.example.eventdispatch I/XQLOG: setOnLongClickListener
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP
05-05 09:38:49.431 23575-23575/com.example.eventdispatch I/XQLOG: setOnClickListener



2、view OnTouchListener true  setOnLongClickListener false   onTouchEvent super.onTouchEvent(event)  dispatchTouchEvent super.dispatchTouchEvent(ev)
05-05 09:43:24.331 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:43:24.341 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:43:24.351 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:43:24.451 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:43:24.461 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:43:24.461 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP


3、view OnTouchListener false  setOnLongClickListener false   onTouchEvent super.onTouchEvent(event)  dispatchTouchEvent true
05-05 09:43:24.331 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:43:24.341 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:43:24.351 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:43:24.451 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:43:24.461 24500-24500/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:43:24.461 24500-24500/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP


4、view OnTouchListener false  setOnLongClickListener true   onTouchEvent super.onTouchEvent(event)  dispatchTouchEvent super.dispatchTouchEvent(ev)
短按
05-05 09:46:50.841 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:46:50.841 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:46:50.841 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-05 09:46:51.251 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:46:51.251 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:46:51.251 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:46:51.261 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:46:51.261 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP
05-05 09:46:51.261 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP
05-05 09:46:51.261 32525-32525/com.example.eventdispatch I/XQLOG: setOnClickListener
长按
05-05 09:48:14.301 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:48:14.301 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:48:14.301 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-05 09:48:14.721 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:48:14.721 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:48:14.721 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:48:14.811 32525-32525/com.example.eventdispatch I/XQLOG: setOnLongClickListener
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP
05-05 09:48:14.921 32525-32525/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP




5、view OnTouchListener false  setOnLongClickListener false   onTouchEvent true  dispatchTouchEvent super.dispatchTouchEvent(ev)
05-05 09:52:08.351 6111-6111/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_DOWN
05-05 09:52:08.361 6111-6111/com.example.eventdispatch I/XQLOG: onTouch ACTION_DOWN
05-05 09:52:08.361 6111-6111/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_DOWN
05-05 09:52:08.371 6111-6111/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_MOVE
05-05 09:52:08.371 6111-6111/com.example.eventdispatch I/XQLOG: onTouch ACTION_MOVE
05-05 09:52:08.371 6111-6111/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_MOVE
05-05 09:52:08.411 6111-6111/com.example.eventdispatch I/XQLOG: textView_dispatchTouchEvent_ACTION_UP
05-05 09:52:08.411 6111-6111/com.example.eventdispatch I/XQLOG: onTouch ACTION_UP
05-05 09:52:08.411 6111-6111/com.example.eventdispatch I/XQLOG: textView_onTouchEvent_ACTION_UP

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

view的测试

package com.example.eventdispatch.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.TextView;

/**
 * Created by xiaquan on 2017/5/4.
 */
public class CustomTextView extends TextView {

    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("XQLOG", "textView_dispatchTouchEvent_ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("XQLOG", "textView_dispatchTouchEvent_ACTION_MOVE");

                break;
            case MotionEvent.ACTION_UP:
                Log.i("XQLOG", "textView_dispatchTouchEvent_ACTION_UP");
                break;

        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("XQLOG", "textView_onTouchEvent_ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("XQLOG", "textView_onTouchEvent_ACTION_MOVE");

                break;
            case MotionEvent.ACTION_UP:
                Log.i("XQLOG", "textView_onTouchEvent_ACTION_UP");
                break;

        }
        return true;
    }



}

package com.example.eventdispatch;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main01);
        tv = (TextView) findViewById(R.id.tv);
        tv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();

                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("XQLOG", "onTouch ACTION_DOWN");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.i("XQLOG", "onTouch ACTION_MOVE");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("XQLOG", "onTouch ACTION_UP");
                        break;
                    default:
                        break;
                }

                return false;
            }
        });
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("XQLOG","setOnClickListener");
            }
        });

        tv.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Log.i("XQLOG","setOnLongClickListener");
                return false;
            }
        });
    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.eventdispatch.MainActivity">

    <com.example.eventdispatch.widget.CustomTextView
        android:id="@+id/tv"
        android:clickable="true"
        android:layout_width="400px"
        android:layout_height="400px"
        android:text="Hello World!" />
</RelativeLayout>
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

viewgroup的测试代码

package com.example.eventdispatch.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;

/**
 * Created by xiaquan on 2017/5/4.
 */
public class CustomLinearLayout extends LinearLayout {
    public CustomLinearLayout(Context context) {
        super(context);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("XQLOG", "ll_dispatchTouchEvent_ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("XQLOG", "ll_dispatchTouchEvent_ACTION_MOVE");

                break;
            case MotionEvent.ACTION_UP:
                Log.i("XQLOG", "ll_dispatchTouchEvent_ACTION_UP");
                break;

        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("XQLOG", "ll_onInterceptTouchEvent_ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("XQLOG", "ll_onInterceptTouchEvent_ACTION_MOVE");

                break;
            case MotionEvent.ACTION_UP:
                Log.i("XQLOG", "ll_onInterceptTouchEvent_ACTION_UP");
                break;

        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("XQLOG", "ll_onTouchEvent_ACTION_DOWN");

                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("XQLOG", "ll_onTouchEvent_ACTION_MOVE");

                break;
            case MotionEvent.ACTION_UP:
                Log.i("XQLOG", "ll_onTouchEvent_ACTION_UP");
                break;

        }
        return super.onTouchEvent(event);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<com.example.eventdispatch.widget.CustomLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.eventdispatch.MainActivity">

    <com.example.eventdispatch.widget.CustomTextView
        android:id="@+id/tv"
        android:clickable="true"
        android:layout_width="400px"
        android:layout_height="400px"
        android:text="Hello World!" />
</com.example.eventdispatch.widget.CustomLinearLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值