01 |
<? xml version = "1.0" encoding = "utf-8" ?> |
02 |
< test.lzqdiy.MyLinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
03 |
android:orientation = "vertical" |
04 |
android:layout_width = "fill_parent" |
05 |
android:layout_height = "fill_parent" |
06 |
android:gravity = "center" > |
07 |
< test.lzqdiy.MyTextView |
08 |
android:layout_width = "200px" |
09 |
android:layout_height = "200px" |
10 |
android:id = "@+id/tv" |
11 |
android:text = "lzqdiy" |
12 |
android:textSize = "40sp" |
13 |
android:textStyle = "bold" |
14 |
android:background = "#FFFFFF" |
15 |
android:textColor = "#0000FF" /> |
16 |
</ test.lzqdiy.MyLinearLayout > |
001 |
package test.lzqdiy; |
002 |
003 |
import android.app.Activity; |
004 |
import android.os.Bundle; |
005 |
006 |
public class TestTouchEventApp extends Activity { |
007 |
/** Called when the activity is first created. */ |
008 |
@Override |
009 |
public void onCreate(Bundle savedInstanceState) { |
010 |
super .onCreate(savedInstanceState); |
011 |
setContentView(R.layout.main); |
012 |
} |
013 |
} |
014 |
package test.lzqdiy; |
015 |
016 |
import android.content.Context; |
017 |
import android.util.AttributeSet; |
018 |
import android.util.Log; |
019 |
import android.view.MotionEvent; |
020 |
import android.widget.LinearLayout; |
021 |
022 |
public class MyLinearLayout extends LinearLayout { |
023 |
private final String TAG = "MyLinearLayout" ; |
024 |
025 |
public MyLinearLayout(Context context, AttributeSet attrs) { |
026 |
027 |
super (context, attrs); |
028 |
029 |
Log.d(TAG, TAG); |
030 |
031 |
} |
032 |
033 |
@Override |
034 |
public boolean dispatchTouchEvent(MotionEvent ev) { |
035 |
int action = ev.getAction(); |
036 |
037 |
switch (action) { |
038 |
039 |
case MotionEvent.ACTION_DOWN: |
040 |
041 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_DOWN" ); |
042 |
043 |
break ; |
044 |
045 |
case MotionEvent.ACTION_MOVE: |
046 |
047 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_MOVE" ); |
048 |
049 |
break ; |
050 |
051 |
case MotionEvent.ACTION_UP: |
052 |
053 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_UP" ); |
054 |
055 |
break ; |
056 |
057 |
case MotionEvent.ACTION_CANCEL: |
058 |
059 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_CANCEL" ); |
060 |
061 |
break ; |
062 |
063 |
} |
064 |
return super .dispatchTouchEvent(ev); |
065 |
} |
066 |
067 |
@Override |
068 |
public boolean onInterceptTouchEvent(MotionEvent ev) { |
069 |
070 |
int action = ev.getAction(); |
071 |
072 |
switch (action) { |
073 |
074 |
case MotionEvent.ACTION_DOWN: |
075 |
076 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_DOWN" ); |
077 |
078 |
break ; |
079 |
080 |
case MotionEvent.ACTION_MOVE: |
081 |
082 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_MOVE" ); |
083 |
084 |
break ; |
085 |
086 |
case MotionEvent.ACTION_UP: |
087 |
088 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_UP" ); |
089 |
090 |
break ; |
091 |
092 |
case MotionEvent.ACTION_CANCEL: |
093 |
094 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_CANCEL" ); |
095 |
096 |
break ; |
097 |
098 |
} |
099 |
100 |
return false ; |
101 |
102 |
} |
103 |
104 |
@Override |
105 |
public boolean onTouchEvent(MotionEvent ev) { |
106 |
107 |
int action = ev.getAction(); |
108 |
109 |
switch (action) { |
110 |
111 |
case MotionEvent.ACTION_DOWN: |
112 |
113 |
Log.d(TAG, "---onTouchEvent action:ACTION_DOWN" ); |
114 |
115 |
break ; |
116 |
117 |
case MotionEvent.ACTION_MOVE: |
118 |
119 |
Log.d(TAG, "---onTouchEvent action:ACTION_MOVE" ); |
120 |
121 |
break ; |
122 |
123 |
case MotionEvent.ACTION_UP: |
124 |
125 |
Log.d(TAG, "---onTouchEvent action:ACTION_UP" ); |
126 |
127 |
break ; |
128 |
129 |
case MotionEvent.ACTION_CANCEL: |
130 |
131 |
Log.d(TAG, "---onTouchEvent action:ACTION_CANCEL" ); |
132 |
133 |
break ; |
134 |
135 |
} |
136 |
137 |
return true ; |
138 |
} |
139 |
140 |
} |
141 |
package test.lzqdiy; |
142 |
143 |
import android.content.Context; |
144 |
import android.util.AttributeSet; |
145 |
import android.util.Log; |
146 |
import android.view.MotionEvent; |
147 |
import android.widget.TextView; |
148 |
149 |
public class MyTextView extends TextView { |
150 |
151 |
private final String TAG = "MyTextView" ; |
152 |
153 |
public MyTextView(Context context, AttributeSet attrs) { |
154 |
155 |
super (context, attrs); |
156 |
157 |
} |
158 |
159 |
@Override |
160 |
public boolean dispatchTouchEvent(MotionEvent ev) { |
161 |
int action = ev.getAction(); |
162 |
163 |
switch (action) { |
164 |
165 |
case MotionEvent.ACTION_DOWN: |
166 |
167 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_DOWN" ); |
168 |
169 |
break ; |
170 |
171 |
case MotionEvent.ACTION_MOVE: |
172 |
173 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_MOVE" ); |
174 |
175 |
break ; |
176 |
177 |
case MotionEvent.ACTION_UP: |
178 |
179 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_UP" ); |
180 |
181 |
break ; |
182 |
183 |
case MotionEvent.ACTION_CANCEL: |
184 |
185 |
Log.d(TAG, "onTouchEvent action:ACTION_CANCEL" ); |
186 |
187 |
break ; |
188 |
189 |
} |
190 |
return super .dispatchTouchEvent(ev); |
191 |
} |
192 |
193 |
@Override |
194 |
public boolean onTouchEvent(MotionEvent ev) { |
195 |
196 |
int action = ev.getAction(); |
197 |
198 |
|