android学习笔记之运动事件MotionEvent
来源:互联网 发布:跟兄弟连学php.pdf下载 编辑:程序博客网 时间:2024/05/19 19:31
运动事件的处理
1.概述
在android中,触摸屏和滚动球的实现,主要可以通过使用运动事件( MotionEvent)用于接收它们的信息。
public boolean onTouchEvent(MotionEvent event)public boolean onTrackballEvent(MotionEvent event)
触摸屏和滚动球事件主要通过实现以下上2 个函数来接收。
2.运行结果
.
3.布局文件 AndroidManifest.xml 的内容如下所示:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.testmotionevent" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.testmotionevent.TestMotionEvent" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
4.程序的代码如下所示:
package com.example.testmotionevent;import android.os.Bundle;import android.app.Activity;import android.util.Log;import android.view.Menu;import android.view.MotionEvent;import android.widget.TextView;public class TestMotionEvent extends Activity { private static final String TAG="TestMotionEvent"; TextView mAction; TextView mPosition; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_motion_event); mAction=(TextView)findViewById(R.id.action); mPosition=(TextView)findViewById(R.id.positon); } public boolean onTouchEvent(MotionEvent event){ int Action =event.getAction(); float X=event.getX(); float Y=event.getY(); Log.v(TAG,"Action="+Action); Log.v(TAG,"("+X+","+Y+")"); mAction.setText("Action="+Action); mPosition.setText("Position=("+X+","+Y+")"); return true; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.test_motion_event, menu); return true; }}
MotionEvent 是用于处理运动事件的类,这个类中可以获得动作的类型、动作的坐标,MotionEvent 中还包含了多点触摸的信息,当有多个触点同时起作用的时候,可以获得触点的数目和每一个触点的坐标。
0 0
- android学习笔记之运动事件MotionEvent
- android 学习之触摸事件 -- 认识MotionEvent
- Android事件处理之MotionEvent
- Android 笔记 motionEvent 处理触摸事件
- 【Android开发学习笔记】【第十课】运动事件 之——触摸屏
- Android模拟MotionEvent事件
- Android学习记录:MotionEvent,onTouch,OnTouchListener 事件机制等学习
- 天天记录 - Android Touch事件学习 - 修改MotionEvent的值
- android之uiaotumation与instrumentation注入MotionEvent和KeyEvent事件
- Android 手势&触摸事件 MotionEvent
- android MotionEvent.ACTION_DOWN 事件丢失
- Android 手势&触摸事件 MotionEvent
- Android MotionEvent事件响应机制
- Android 手势&触摸事件 MotionEvent
- Android 手势&触摸事件 MotionEvent
- Androin学习笔记五十八:android触控,先了解MotionEvent
- android学习笔记之事件处理机制
- android-学习笔记之按钮事件
- HDU Problem - 5363 Key Set 【快速幂】
- POJ1325
- 关于Cache-Control: no-cache和no-store
- linux中设置环境变量和gcc/g++的include路径
- 利用docker-compose和docker-swarm搭建ELK环境
- android学习笔记之运动事件MotionEvent
- WWW-万维网详解
- MyEclipse——快捷键的使用
- 进阶项目1-递归函数.立方和累加
- hadoop map 与reduce 的流程
- android面试专题(4)
- 嵌入式学习-驱动开发前奏-lesson4-驱动分类和硬件访问相关
- CSAPP: Malloc lab
- sublime text3 css3前缀自动补充插件