码迷,mamicode.com
首页 > 其他好文 > 详细

人脸识别之触摸图片显示对应的文字

时间:2014-10-18 16:47:01      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   io   os   ar   java   

人脸识别之触摸图片显示对应的文字

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:textColor="#FFFFFF" 
    android:background="@drawable/renwu" (插入你所需要插入的图片,显示在程序的上方)
    android:text="触摸事件测试区域"> 
</TextView>

<TextView 
    android:id="@+id/event_label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="" >(用来显示你触摸图片对应显示的内容)
</TextView>
</LinearLayout>

java文件:

package com.TouchEventDemo;

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

public class TouchEventDemo extends Activity {
    private TextView labelView,touchView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        labelView=(TextView)findViewById(R.id.event_label);
        
        touchView=(TextView)findViewById(R.id.touch_area);
        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_MOVE): 
				    Display("ACTION_MOVE",event); 
				    break;
				}
				return true;
			}
		});
    }
 private void Display(String eventType, MotionEvent event){ 
    	int x = (int)event.getX(); 
    	int y = (int)event.getY(); 
    	String msg1 = ""; 
    	if(x>105&&x<190&&y>192&&y<208) 
    	{
    		msg1 +="你摸到我的鼻子了"+"\n";
    	}
    	else if(x>95&&x<130&&y>160&&y<180)
    	{
    		msg1 +="你摸到我的眼睛了"+"\n";
    	}
    	else if(x>140&&x<170&&y>230&&y<250)
    	{
    		msg1 +="你摸到我的嘴了"+"\n";
    	}
    		
    	msg1 += "相对坐标:"+String.valueOf(x)+","+String.valueOf(y)+"\n"; (通过这个获取你所触摸区域的相对坐标,记录下来,以方便写 if 语句)
    	
    	
    	labelView.setText(msg1); 
     } 
}

 

运行结果截图:

bubuko.com,布布扣

人脸识别之触摸图片显示对应的文字

标签:android   style   blog   http   color   io   os   ar   java   

原文地址:http://www.cnblogs.com/penger/p/4033206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!