当前位置: 代码迷 >> Android >> android抚摸实现方式
  详细解决方案

android抚摸实现方式

热度:68   发布时间:2016-05-01 15:49:31.0
android触摸实现方式

android触摸实现方式

package com.ray.touch;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;
import android.widget.Toast;

public class TouchPaint extends Activity {
??? TextView tv;
??? @Override
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
??????? tv = (TextView) findViewById(R.id.tv);
??? }

@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch(event.getAction()){
case MotionEvent.ACTION_DOWN: tv.setText("down"+"("+x+","+y+")");break;
case MotionEvent.ACTION_UP: tv.setText("up"+"("+x+","+y+")");break;
case MotionEvent.ACTION_MOVE:tv.setText("move"+"("+x+","+y+")");break;
}
return super.onTouchEvent(event);
}
}
  相关解决方案