package com.cky.learnandroiddetails;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

public class TestViewGroupEventActivity extends AppCompatActivity {

    private static final String TAG = TestDispatchEventActivity.class.getSimpleName();

    /*
    *当点击某个控件 首先会去调用该控件所在布局的dispatchTouchEvent方法
    *然后在布局的dispatchTouchEvent的方法中找到被点击的相应控件
    * 再去调用该控件的dispatchTouchEvent方法
    *
    * */
    MyLayout myLayout;
    Button mButton1;
    Button mButton2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_view_group_event);

        myLayout = (MyLayout) findViewById(R.id.myLayout);
        mButton1 = (Button) findViewById(R.id.button1);
        mButton2 = (Button) findViewById(R.id.button2);

        myLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.d(TAG, "myLayout on touch");
                return false;
            }
        });

        mButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "button1 on click");
            }
        });

        mButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "button2 on click");
            }
        });
    }
}

@@ -517,16 +517,517 @@
 %E6%96%B9%E6%B3%95%0A    *
+ */%0A%0A    /*%0A    *%0A    * View %E7%9A%84%E4%BD%8D%E7%BD%AE%E5%8F%82%E6%95%B0%0A    * top left right bottom%0A    *%0A    * %E7%9B%B8%E5%AF%B9%E4%BA%8E View%E7%9A%84%E7%88%B6%E5%AE%B9%E5%99%A8%E8%80%8C%E8%A8%80%E7%9A%84%0A    *%0A    * top %E5%B7%A6%E4%B8%8A%E8%A7%92%E7%BA%B5%E5%9D%90%E6%A0%87%0A    * left %E5%B7%A6%E4%B8%8A%E8%A7%92%E6%A8%AA%E5%9D%90%E6%A0%87%0A    * right %E5%8F%B3%E4%B8%8B%E8%A7%92%E6%A8%AA%E5%9D%90%E6%A0%87%0A    * bottom %E5%8F%B3%E4%B8%8B%E8%A7%92%E7%BA%B5%E5%9D%90%E6%A0%87%0A    *%0A    * width = right - left%0A    * height = bottom - top%0A    *%0A    * x = left + translationX(%E9%BB%98%E8%AE%A40)%0A    * y = top + translationY(%E9%BB%98%E8%AE%A40)%0A    *%0A    * %E5%9C%A8View %E7%9A%84%E5%B9%B3%E7%A7%BB%E8%BF%87%E7%A8%8B%E4%B8%AD top left%E8%A1%A8%E7%A4%BA%E5%8E%9F%E5%A7%8B%E5%B7%A6%E4%B8%8A%E8%A7%92%E7%9A%84%E4%BD%8D%E7%BD%AE %E4%B8%8D%E5%8F%91%E7%94%9F%E6%94%B9%E5%8F%98%0A    *%0A    * MotionEvent%0A    * getX/getY %E8%8E%B7%E5%BE%97%E7%9B%B8%E5%AF%B9%E4%BA%8E%E5%BD%93%E5%89%8DView%E5%B7%A6%E4%B8%8A%E8%A7%92%E7%9A%84x%E5%92%8Cy%E5%9D%90%E6%A0%87%0A    * getRawX/getRawY %E8%8E%B7%E5%BE%97%E7%9B%B8%E5%BD%93%E4%BA%8E%E6%89%8B%E6%9C%BA%E5%B1%8F%E5%B9%95%E5%B7%A6%E4%B8%8A%E8%A7%92%E7%9A%84x%E5%92%8Cy%E5%9D%90%E6%A0%87%0A    *%0A    * TouchSlop%0A    * %E7%B3%BB%E7%BB%9F%E6%89%80%E8%83%BD%E8%AF%86%E5%88%AB%E7%9A%84%E6%BB%91%E5%8A%A8%E7%9A%84%E6%9C%80%E5%B0%8F%E8%B7%9D%E7%A6%BB
 %0A    * *
@@ -1028,16 +1028,17 @@
    * */%0A
+%0A
     MyLa

更新 View 相关