package cn.c; import android.os.Bundle; import android.app.Activity; import android.view.MotionEvent; import android.widget.Button; /** * Demo描述: * 在MainActivity的dispatchTouchEvent方法中直接将事件指定给了MyButton * 比较简单,参见代码即可 * * 备注说明: * 其他的代码和前几个例子一样,故不再贴出. * */ public class MainActivity extends Activity { private Button myButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myButton=(Button) findViewById(R.id.button); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { return myButton.dispatchTouchEvent(ev); } @Override public void onUserInteraction() { super.onUserInteraction(); } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: break; } return super.onTouchEvent(event); } }
时间: 2024-11-08 20:15:24