Search code examples
androidandroid-widgetcoordinates

Widget child view coordinates?


In an activity we can use getIntent() to get coordinates of top and left corner of view that request to start an Activity:

top = this.getIntent().getSourceBounds().top;
left = this.getIntent().getSourceBounds().left;     

So if a widget request to start an Activity,we can get it's top and left corner coordinates.But if a child view of widget(like a button or textview) apply to start an Activity,how we can get coordinates of top and left corner of widget?


Solution

  • I did not find any method to get parent view's coordinates,so I use relative layout for widget and set textview layout_alignParentLeft and layout_alignParentTop with "true",and then set other controls in front of it.As result when user clicks on textview,textview send it's coordinates with intent that it is equal to it's parent coordinates.