Facial recognition-text corresponding to the display of touch Images

Source: Internet
Author: User

Facial recognition-text corresponding to the display of touch Images

XML file:

<? 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" (insert the picture you want to insert and display it above the program) Android: TEXT = "Touch event test area"> </textview> <textview Android: Id = "@ + ID/event_label" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = ""> (used to display the content displayed when you touch an image) </textview> </linearlayout>

Java file:

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 + = "you have touched my nose" + "\ n ";} else if (x> 95 & x <130 & Y> 160 & Y <180) {msg1 + = "you have touched my eyes" + "\ n ";} else if (x> 140 & x <170 & Y> 230 & Y <250) {msg1 + = "you have touched my mouth" + "\ n";} msg1 + = "relative coordinate:" + String. valueof (x) + "," + String. valueof (y) + "\ n"; (use this to obtain the relative coordinates of the area you are touching, and record it to facilitate the write if statement) labelview. settext (msg1 );}}

 

Running result:

Facial recognition-text corresponding to the display of touch Images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.