效果图:



代码部分:

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>字符串处理代码

    字符串处理:        strlen("aaa");取字符串的长度 ***    strcmp("aaa","aaa");比较两个字符串 ...

  2. Java中BigDecimal的8种舍入模式是怎样的

    Java中BigDecimal的8种舍入模式是怎样的?下面长沙欧柏泰克软件学院和大家一起来学习下吧:  java.math.BigDecimal 不可变的.任意精度的有符号十进制数.BigDecima ...

  3. poj 3187 Backward Digit Sums(穷竭搜索dfs)

    Description FJ and his cows enjoy playing a mental game. They write down the numbers to N ( <= N ...

  4. UVA 10400 Game Show Math (dfs + 记忆化搜索)

    Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...

  5. c++11 : range-based for loop

    0. 形式 for ( declaration : expression ) statement 0.1 根据标准将会扩展成这样的形式: 1   { 2     auto&& __ra ...

  6. asp.net 实现 tts

    之前用WinForm实现tts已经成功,就调用了下系统的类库.但我把相同的代码搬到asp.net上时却碰到了许多问题,查了好多网站.试过了很多方法,到现在算是做出了一部分吧. 之前调用微软的TTS是用 ...

  7. 连接Oracle11g数据库时遇到无监听,网络适配器无法建立等问题的一些解决办法

    最近在用Java做一个学生成绩管理系统,打算用Oracle数据库.由于原先没接触过Oracle,所以安装完数据库后,连接数据库时遇到各种问题,网上搜索解决方案还是没有解决时,又重新安装了几次.终于在前 ...

  8. visifire 图表属性样式设置说明,字体,阴影设置

  9. Jquery常用方法(转)

    原文:http://www.cnblogs.com/Chenfengtao/archive/2012/01/12/2320490.html jQuery是目前使用最广泛的javascript函数库.据 ...

  10. 删除作业计划出错(DELETE语句与 REFERENCE约束"FK_subplan_job_id"冲突。)

    删除作业计划出错(DELETE语句与 REFERENCE约束"FK_subplan_job_id"冲突.) use msdb select * from sysmaintplan_plans --查看 ...