设为首页 加入收藏

TOP

Android--多点触控事件捕捉
2014-11-24 08:24:44 来源: 作者: 【 】 浏览:1
Tags:Android-- 事件 捕捉

下面给出实现的截图对比:




下面给出本实例的源代码:


package irdc.ex07_20;


import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;


public class EX07_20 extends Activity
{
private TextView myText1;
private TextView myText2;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* 加载main.xml Layout */
setContentView(R.layout.main);
/* TextView初始化 */
myText1=(TextView)findViewById(R.id.text1);
myText2=(TextView)findViewById(R.id.text2);
}

/* 重写onTouchEvent() */
@Override
public boolean onTouchEvent(MotionEvent event)
{
/* 显示触碰点的数量 */
myText2.setText(""+event.getPointerCount());

/* event的Action 断 */
switch(event.getAction())
{
/* 触碰事件发生 */
case MotionEvent.ACTION_DOWN:
myText1.setText(getResources().getString(R.string.act1));
break;
/* 触碰事件结束 */
case MotionEvent.ACTION_UP:
myText1.setText(getResources().getString(R.string.act2));
/* 显示点数为0 */
myText2.setText("0");
break;
/* 第1个触碰点被按下 */
case MotionEvent.ACTION_POINTER_1_DOWN:
myText1.setText(getResources().getString(R.string.act3));
break;
/* 第1个触碰点被移除 */
case MotionEvent.ACTION_POINTER_1_UP:
myText1.setText(getResources().getString(R.string.act4));
break;
/* 第2个触碰点被按下 */
case MotionEvent.ACTION_POINTER_2_DOWN:
myText1.setText(getResources().getString(R.string.act5));
break;
/* 第2个触碰点被移除 */
case MotionEvent.ACTION_POINTER_2_UP:
myText1.setText(getResources().getString(R.string.act6));
break;
default:
break;
}
return super.onTouchEvent(event);
}
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇100多个Android Demo的整合下载 下一篇Android--手势触控屏幕控制/Gestu..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)