我的学习视频地址,一起来学习Android…
http://edu.csdn.net/course/detail/2741/43164?auto_start=1>
代码下载地址
代码一:自定义支持多点触摸的TextView
http://download.csdn.net/detail/zhiyuan0932/9513852
什么是多点触摸
允许计算机用户同时通过多个手指来控制图形界面的一种技术
多点触摸的应用场景
- 对图片、文字、网页进行放大或者缩小
- 多手指手势操作自定义控件和布局
触摸事件的重要方法
event.getActionMasked(); 获取事件类型
在只使用单手指操作的时候,这个方法我们一般使用的是event.getAction(),来获取事件类型,但是对于多个手指,我们使用event.getActionMasked()或者event.getAction() & MotionEvent.ACTION_MASK 来获取支持多个手指触摸的事件类型。MotionEvent.ACTION_POINTER_DOWN 手指按下事件
这个方法可以获取到多个手指按下的状态MotionEvent.ACTION_POINTER_UP 手指抬起事件
这个方法可以获取到多个手指抬起的状态MotionEvent.ACTION_MOVE 手指移动事件
event.getPointerCount() 获取手指个数
这个方法是获取当前手指的个数
案例一:通过两指触摸实现字体缩放
- 在这里直接贴代码,首先贴出布局代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.scaletextview.ZoomTextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/hello_world"
android:textSize="30sp" />
</RelativeLayout>
- 贴出自定义支持多点触控的TextView代码
package com.example.scaletextview;
import android.content.Context;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.TextView;
public class ZoomTextView extends TextView {
private static final String TAG = "ZoomTextView";
private float textSize;
private int mode;
private float oldDist;
public ZoomTextView(Context context, Attrib