多数安卓软件都需要获取用户手指操作的坐标和一些用户的操作,这里写一个小demo来演示如何通过事件获取这些信息用以记录,以备日后查询。
只有一个界面,故在Android Studio中新建项目后,编写MainActivity.java和activity_main.xml即可,如图:
activity_main.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/touch_area"
android:layout_width="fill_parent"
android:layout_height="300dip"
android:background="@color/black"
android:textColor="@color/white"
android:textSize="50dp"
android:text="触摸事件测试区"/>
<TextView
android:id="@+id/history_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="history data"/>
<TextView
android:id="@+id/event_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="touch event:"