android触摸事件

package com.example.touch_1;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.RelativeLayout;import android.widget.Toast;public class MainActivity extends Activity implements OnTouchListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);     ////1111RelativeLayout myLayout = (RelativeLayout) findViewById(R.id.myLayout);///222myLayout.setOnTouchListener(this);/////3333这三句话的顺序很重要}@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "发生触摸", Toast.LENGTH_SHORT).show();return false;}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/myLayout"////这里要加id    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="${relativePackage}.${activityClass}" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>



更多相关文章

  1. android 电容屏(一):电容屏基本原理篇
  2. 【Android每周专题】触摸屏手势
  3. android 电容屏(三):驱动调试之驱动程序分析篇
  4. android 电容屏(一):电容屏基本原理篇
  5. android GestureDetector应用
  6. android跑马灯有时候不跑
  7. Android(安卓)Gesture Detector
  8. Android(安卓)(layout_toLeftOf,layout_toRightOf,layout_above,
  9. 箭头图标不显示

随机推荐

  1. Android 游戏引擎libgdx 锁屏、电话等引
  2. Android获取SD卡上图片和视频文件及其缩
  3. android 增加新按键
  4. android ndk不支持宽字符转换
  5. android真机测试问题
  6. 九宫格的实现及九宫格源码
  7. android opengl es 简单实例
  8. Android ormlite 框架介绍
  9. 【总结备用】Android监听网络状态实现(Br
  10. Android底部导航栏,三种风格和实现