加载中…
个人资料
baohanqing
baohanqing
  • 博客等级:
  • 博客积分:0
  • 博客访问:1,450
  • 关注人气:42
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Android开发之触摸事件-点击屏幕获得屏幕的坐标

(2013-02-01 16:49:29)
标签:

android

安卓

安卓触摸事件

安卓获取屏幕坐标

it

分类: android
http://s12/mw690/7256fe8fgd4a5d44cef7b&690

.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;
}
}
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有