Note/安卓/第十章:Android 事件处理.md
2023-08-31 11:30:31 +08:00

48 lines
1.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 第十章Android 事件处理
1.事件分为:键盘事件、触摸事件
2.处理事件的两种方式:
1.基于回调机制
回调on开头的方法返回值true,代表事件处理完毕;
2.基于监听接口
10.4 手势
案例一:创建并保存手势
1.创建项目并复制布局文件
案例:手势识别
1.创建项目 `AddGesture`
2.将 `AddGesture` 中的 `mygestur` 放到 `GestureRecognition` 项目下的 `res` --> `raw `
3.布局文件
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="手势"
android:textColor="@android:color/black"
android:textSize="20dp" />
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />
</LinearLayout>
```
方法2直接在SD卡里面试别