效果图:



代码部分:

activity类代码:

package com.TouchView;
/*
* android滑动基础篇
* */ import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView; public class TouchView extends Activity { private TextView eventlable; //触摸事件
private TextView histroy; //历史数据
private TextView TouchView; //触摸事件测试区 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TouchView =(TextView)findViewById(R.id.touch_area);
histroy =(TextView)findViewById(R.id.history_label);
eventlable =(TextView)findViewById(R.id.event_label); /*设置触摸监听*/
TouchView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) {
int action =event.getAction();
switch(action){
//当按下的时候
case (MotionEvent.ACTION_DOWN):
Display("ACTION_DOWN",event);
break;
//当按上的时候
case(MotionEvent.ACTION_UP):
int historysize=ProcessHistory(event);
histroy.setText("历史数据: "+historysize);
Display("ACTION_UP",event);
break;
//当触摸的时候
case(MotionEvent.ACTION_MOVE):
Display("ACTION_MOVE",event);
}
return true;
}
});
} //显示事件类型以及事件信息(坐标,压力,尺寸,时间等)
public void Display(String eventType,MotionEvent event){
//触点相对坐标的信息
int x =(int) event.getX();
int y=(int)event.getY();
//表示触屏压力大小
float pressure =event.getPressure();
//表示触点尺寸
float size=event.getSize();
//获取绝对坐标信息
int RawX=(int)event.getRawX();
int RawY=(int)event.getRawY(); String msg="触摸事件:\n";
msg+="事件类型"+eventType+"\n";
msg+="相对坐标"+String.valueOf(x)+","+String.valueOf(y)+"\n";
msg+="绝对坐标"+String.valueOf(RawX)+","+String.valueOf(RawY)+"\n";
msg+="触点压力"+String.valueOf(pressure)+" , ";
msg+="触点尺寸"+String.valueOf(size)+"\n";
eventlable.setText(msg);
} /*可以通过调用getHistorySize来获得历史的大小值,它可以返回当前事件可用的运动位置的数目。
* 然后你可以通过使用一系列getHistorical*方法,并传递给它位置索引,来获得每一个历史事件的时间、压力、大小和位置*/
public int ProcessHistory(MotionEvent event){
int historysize =event.getHistorySize(); // 获取历史采样的集合大小
for(int i=0;i<historysize;i++){
long time=event.getHistoricalEventTime(i); // 历史采样的时间点
float pressure=event.getHistoricalPressure(i);
float x=event.getHistoricalX(i) ;
float y=event.getHistoricalY(i);
float size=event.getHistoricalSize(i);
}
return historysize;
}
}

MAIN.XML代码部分:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="360dip"
android:background="#0FF"
android:textColor="#FFFFFF"
android:text="触摸事件测试区" /> <TextView
android:id="@+id/history_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#006400"
android:text="历史数据" /> <TextView
android:id="@+id/event_label"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#C0C0C0"
android:textColor="#000000"
android:text="触摸事件:" /> </LinearLayout>

android滑动基础篇 - 触屏显示信息的更多相关文章

  1. android滑动基础篇 TouchView

    效果图: 代码部分: activity类代码: package com.TouchView; import android.app.Activity; import android.os.Bundle ...

  2. Android - 设置ImageView为全屏显示

    设置ImageView为全屏显示 本文地址: http://blog.csdn.net/caroline_wendy ImageView默认会适应屏幕大小, 假设想使用全屏填充, 则须要使用: and ...

  3. Android之怎样强制横竖屏显示

    2  强制横屏竖屏显示(不依据手机传感器调整) 在清单文件AndroidManifest.xml中 在<activity 里面增加: android:screenOrientation=&quo ...

  4. OpenCV基础篇之读取显示图片

    程序及分析 /* * FileName : read.cpp * Author : xiahouzuoxin @163.com * Version : v1.0 * Date : Tue 13 May ...

  5. (spring-第14回【IoC基础篇】)国际化信息

    国际化又称为本地化. 当你把手机的language由中文切换到英文时,你的微信也相应改用英语,这就是i18n国际化.一般来说,应用软件提供一套不同语言的资源文件,放到特定目录中,应用根据不同语言的操作 ...

  6. Android中界面实现全屏显示的两种方式

    在开发android的应用当中,我们会遇到将一些界面设置为全屏显示的格式,有两种实现的方法.其一是在Java代码中实现,其二是在配置文件中实现. 1. 在Java代码中设置 super.onCreat ...

  7. (spring-第14回【IoC基础篇】)国际化信息 (转)

    国际化又称为本地化. 当你把手机的language由中文切换到英文时,你的微信也相应改用英语,这就是i18n国际化.一般来说,应用软件提供一套不同语言的资源文件,放到特定目录中,应用根据不同语言的操作 ...

  8. Android开发 - 设置DialogFragment全屏显示

    默认的DialogFragment并不是全屏,但有些需求需要我们将对话框设置为全屏(内容全屏),Android并没有提供直接的API,通过其它不同的方法设置全屏在不同的机型上总有一些诡异的问题,经过测 ...

  9. nes 红白机模拟器 第5篇 全屏显示

    先看一下效果图 放大的原理是使用最初级的算法,直接取对应像素法. /*================================================================= ...

随机推荐

  1. <php>删除(有内容的)文件夹函数程序

    function deldir($dirname) { if(!file_exists($dirname)) {//判断文件夹是否存在 die("文件夹不存在!");//作用等于( ...

  2. mysql下用户和密码生成管理

    应用上线,涉及到用户名和密码管理,随着上线应用的增加,用户名和密码的管理设置成为一个问题.还要对用户赋权,于是想着写一个脚本来管理,看到同事写的一个脚本,满足需求.思路大致是字母替换为数字,账号根据库 ...

  3. Unity 3D 动画帧事件

    前几天在项目开发中碰到一个这样的需求,RPG游戏中,特效和动画播放不同步的.假如主角在攻击NPC时,先实例化特效,后播放动画.动画毕竟是有一个时间长度的.等到动画播放攻击挥刀的那一瞬间时,特效可能早就 ...

  4. open(),close() 打开/关闭文件

    Open open()是一个系统调用函数,用来打开或创建一个文件,通过不同的oflag选项实现不同功能. 使用时open()函数需要包含的头文件:<sys/types.h>,<sys ...

  5. My way on Linux - [Shell基础] - Bash Shell中判断文件、目录是否存在或者判断其是否具有某类属性(权限)的常用方法

    Conditional Logic on Files # 判断文件是否存在及文件类型 -a file exists. #文件存在 -b file exists and is a block speci ...

  6. CodeSmith使用总结--创建一个基础模板

    问:为什么要用CodeSmith? 答曰:因为我懒的写. Codesmith是一款非常不错的懒人工具,我也经常会用到,因为它在“重复代码”方面能够节省我们很多时间,并且解除了我们重复繁琐并且乏味的“码 ...

  7. 中控考勤机-C#操作

    引用:Interop.zkemkeeper.dll 实例化: public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM(); 首先从数据库中获取考 ...

  8. ie8 hack

    1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...

  9. (转)jQuery插件开发模式

    要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...

  10. Label 表达式绑定

    Text='<%#"总金额为: "+Convert.ToString(Convert.ToDecimal(TextBox1.Text)*Convert.ToInt32(Tex ...