java - Top Left Coordinates of ImageView in Android displaying incorrectly -


i have imageview in activity, top left coordinates must retrieve can divide the imageview 5 touch zones. use getlocationonscreen these coordinates.

the x coordinate fine y coordinate seems faulty reason, there offset , seems point top of window( verified enabling pointer touches in dev tools).

here activity code:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     this.requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.activity_main);      amslerview = (imageview) findviewbyid(r.id.amsler_grid);      loctext = (textview) findviewbyid(r.id.locationlabel);      amslerview.setontouchlistener(new ontouchlistener()     {          @override         public boolean ontouch(view v, motionevent event)         {             switch (event.getaction())             {                 case motionevent.action_down :                     startx = (int) event.getrawx();                     starty = (int) event.getrawy();                      int[] loc = new int[2];                     amslerview.getlocationonscreen(loc);                     log.i("screen location of view", "x:" + loc[0] + "\t y:" + loc[1]);                      loctext.settext("location " + startx + " " + starty + "screen view location " + "x:" + loc[0] + "\t y:" + loc[1]);                      break;                  case motionevent.action_up :                     endx = (int) event.getx();                     endy = (int) event.gety();                      // loctext.settext("end location " + endx + "\t" +                     // endy);                     break;              }              return true;          }     });  } 

here xml layout:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     tools:context=".mainactivity" >      <imageview         android:id="@+id/amsler_grid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:layout_weight="1"         android:adjustviewbounds="true"         android:contentdescription="amsler grid"         android:padding="0dp"         android:scaletype="center"         android:src="@drawable/amsler_boundary" /> 

and screenshot of problem i'm facing: http://puu.sh/4d1lj.jpg

as can see, x coordinate fine, y coordinate shows location http://puu.sh/4d1oj.jpg

any appreciated, i'm frankly @ loss why happening.

finally found wrong, y offset due fact height of both status bar , actionbar taken account. in case offset 108( 75 actionbar , 33 status bar). writing 2 functions calculate these heights , subtracting them value returned getrawy() solved problem.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -