zoukankan      html  css  js  c++  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 +="你摸到我的鼻子了"+"
    ";
        	}
        	else if(x>95&&x<130&&y>160&&y<180)
        	{
        		msg1 +="你摸到我的眼睛了"+"
    ";
        	}
        	else if(x>140&&x<170&&y>230&&y<250)
        	{
        		msg1 +="你摸到我的嘴了"+"
    ";
        	}
        		
        	msg1 += "相对坐标:"+String.valueOf(x)+","+String.valueOf(y)+"
    "; (通过这个获取你所触摸区域的相对坐标,记录下来,以方便写 if 语句)
        	
        	
        	labelView.setText(msg1); 
         } 
    }
    

    运行结果截图:

  • 相关阅读:
    《逍遥法外》观后感
    1237. 螺旋折线
    P2196 挖地雷
    787. 归并排序
    466. 回文日期
    P1032 字串变换
    P1825 [USACO11OPEN]Corn Maze S
    P1162 填涂颜色
    P1101 单词方阵
    P1019 单词接龙
  • 原文地址:https://www.cnblogs.com/penger/p/4033206.html
Copyright © 2011-2022 走看看