Android Screen click Location Test

Source: Internet
Author: User

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <!--defining TextView Text Labels -    <TextViewAndroid:id= "@+id/tv"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "tap the screen to get the position relative to the screen"        /></Relativelayout>
 PackageCom.example.yanlei.yl;ImportAndroid.graphics.Color;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.widget.TextView;Importandroid.text.Html;ImportAndroid.text.Html.ImageGetter;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern;Importandroid.text.Editable;ImportAndroid.text.TextWatcher;ImportAndroid.widget.EditText;ImportAndroid.widget.Button;Importandroid.app.Activity;Importandroid.content.Intent;Importandroid.view.MotionEvent;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {//Defining TextView Objects    PrivateTextView Tv; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //get the control object in the browserFindview (); } @Override Public Booleanontouchevent (Motionevent event) {//when you press the screen, get the X, y of the click position        if(Motionevent.action_down = =event.getaction ()) {            floatx =Event.getx (); floaty =event.gety (); Tv.settext ("The location you clicked is: \nx:" +x+ "\ n y:" +y); }        return Super. Ontouchevent (event); }    Private voidFindview () {//gets the control object for the current layoutTv =(TextView) Findviewbyid (r.id.tv); }}

Android Screen click Location Test

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.