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

    运行结果截图:

  • 相关阅读:
    uvm设计分析——report
    report源码分析——report_handle和report_server和report_catcher
    report源码分析——宏的执行
    015-命令行下载安装brew
    011-多线程-基础-基于AbstractQueuedSynchronizer自定义同步组件
    010-多线程-JUC集合-Queue-ConcurrentLinkedQueue
    009-多线程-JUC集合-Queue-LinkedBlockingDeque
    008-多线程-JUC集合-Queue-LinkedBlockingQueue
    007-多线程-JUC集合-Queue-BlockingQueue接口以及ArrayBlockingQueue
    006-多线程-集合-Set-ConcurrentSkipListSet
  • 原文地址:https://www.cnblogs.com/penger/p/4033206.html
Copyright © 2011-2022 走看看