android滑动基础篇
来源:互联网 发布:淘宝怎么解决管控纪录 编辑:程序博客网 时间:2024/05/01 07:16
因为觉得android用到滑动的地方比较多,所以在写一篇基础的里字..
效果图:
代码部分:
activity类代码:
package com.TouchView;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; @Override 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() {@Overridepublic 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=""; 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); } public int ProcessHistory(MotionEvent event){ int history =event.getHistorySize(); for(int i=0;i<history;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 history; } }
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="300dip" 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:text="历史数据" /> <TextView android:id="@+id/event_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="触摸事件:" /></LinearLayout>
- android滑动基础篇
- android滑动基础篇 TouchView
- Android----ViewPager页面滑动基础--FragmentPagerAdapter篇
- Android----ViewFlipper页面滑动基础
- Android 滑动效果基础篇—— Gallery + GridView
- android滑动基础篇 - 触屏显示信息
- Android----ViewPager页面滑动基础--PagerAdapter篇(一)
- Android----ViewPager页面滑动基础--PagerAdapter篇(二)
- Android基础UI之ViewPager禁止滑动
- Android View滑动相关的基础知识点
- Android 滑动效果基础篇(三)—— Gallery仿图像集浏览
- Android 滑动效果基础篇(四)—— Gallery + GridView
- Android 滑动效果基础篇(四)—— Gallery + GridView
- Android 滑动效果基础篇(三)—— Gallery仿图像集浏览
- Android 滑动效果基础篇(四)—— Gallery + GridView
- Android 滑动效果基础篇(三)—— Gallery仿图像集浏览
- Android 滑动效果基础篇(四)—— Gallery + GridView
- Android 滑动效果基础篇(三)—— Gallery仿图像集浏览
- hdu 1394
- [ActiveRecord] 之四:Cascade
- 树链剖分(QTREE)
- VC6.0中C4541号警告的原因以及解决方案
- 系统架构之二(棋牌类游戏常用架构)
- android滑动基础篇
- [ActiveRecord] 之五:ActiveRecordMediator
- ExpandableListView基本实现—能运行
- 读取RSS源的天气预报Web Server实现
- (2011.07.04-2011.07.09)六天的学习小记
- [ActiveRecord] 之六:继承
- 根据查询的关键字,实现获取百度指定页数的搜索结果的信息(网页地址,标题,摘要,并有排序的说明)
- C++图像处理 -- 图像颜色混合(中)
- 字节对齐