Android开发之触摸事件-点击屏幕获…
2013-12-30 20:39
78 查看
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
.xml文件
<LinearLayout
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"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="点击获取屏幕的坐标" />
</LinearLayout>
.java文件
package
com.example.touchproject;
import
android.os.Bundle;
import
android.app.Activity;
import
android.view.Menu;
import
android.view.MotionEvent;
import
android.view.View;
import
android.view.View.OnTouchListener;
import
android.widget.TextView;
public class MainActivity
extends Activity {
private TextView
info=null;
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.info=(TextView)
super.findViewById(R.id.info);
//添加触摸事件
this.info.setOnTouchListener(new
TouchListenerImp());
}
private class TouchListenerImp
implements OnTouchListener{
public boolean onTouch(View v,
MotionEvent event) {
MainActivity.this.info.setText("x="+event.getX()+"y="+event.getY());
return false;
}
}
}
相关文章推荐
- Android开发-触屏事件的获取和触摸屏幕位置
- 【Android】技术调研:用代码模拟屏幕点击、触摸事件
- 【Android】技术调研:用代码模拟屏幕点击、触摸事件
- cocos2dx-3.6 开发技巧(二)回调函数以及动画的使用,触摸事件,android返回键,屏幕截屏
- Android开发-触屏事件的获取和触摸屏幕位置
- 简单讲解Android开发中触摸和点击事件的相关编程方法
- Android开发-触屏事件的获取和触摸屏幕位置
- Android开发-之监听button点击事件
- Android通过代码模拟物理、屏幕点击事件
- Android 屏幕触摸事件之诡----dispatchTouchEvent,onInterceptTouchEvent,onTouchEvent,onTouch
- Android 横屏启动activity,点击屏幕的单击、双击和长按事件
- Android开发之带CheckBox的ListView的点击事件的处理
- Android开发之--- 监测手机返回键的点击事件
- Cocos2d-x游戏开发——屏幕触摸事件
- android 触摸事件、点击事件的区别
- Android开发给TextView添加点击事件
- Android屏幕点击事件重写
- Android开发——利用ViewPager实现显示多个item无限轮播+点击事件监听
- android 触摸事件、点击事件的区别
- Android 中屏幕点击事件的实现