3

My map activity displaying n number of overlay, when i am tapping on overlay icon then toast is displaying on bottom of screen, But i want to display the Toast near by overlay icon where i am tapping..

Please guide me, Thanks in advance...

Vishesh Chandra
  • 6,861
  • 6
  • 32
  • 38
  • possible duplicate of [how to change position of Toast in android?](http://stackoverflow.com/questions/2506876/how-to-change-position-of-toast-in-android) – Graham Borland May 25 '12 at 15:10

4 Answers4

5

This code is giving me exact position of toast... This code is giving me exact gravity of toast..

OverlayItem item = overlayItems_.get(index);
Projection projection = mMapView.getProjection();
    Point point = new Point();
    projection.toPixels(item.getPoint(), point);
    Toast toast = Toast.makeText(mContext, item.getTitle()+" "+item.getSnippet(), Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, point.x, point.y);
    toast.show();

Here i am passing points also..

Vishesh Chandra
  • 6,861
  • 6
  • 32
  • 38
1

Try looking here:

How to change position of Toast in Android?

It mentions how to position your Toast message using setGravity(). You'll want to use the (x,y) coordinates of your pin to set the location of your Toast.

Community
  • 1
  • 1
jmhend
  • 547
  • 1
  • 6
  • 16
  • Thanks to help me, but this solution is giving the gravity of toast to only LEFT, RIGHT, TOP, BOTTOM, but i need toast gravity where ever i am tapping the overlay icon, Now finally i got solution.. – Vishesh Chandra May 28 '12 at 05:35
1

Positioning your Toast

A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

If you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

Source: Google Developers

jnthnjns
  • 8,942
  • 4
  • 40
  • 65
  • Thanks to help me, but this solution is giving the gravity of toast to only LEFT, RIGHT, TOP, BOTTOM, but i need toast gravity where ever i am tapping the overlay icon, Now finally i got solution.. – Vishesh Chandra May 28 '12 at 05:35
0
toast.setGravity(Gravity.TOP, 0, 0);

Instead of Gravity.TOP you could also use LEFT or RIGHT

Thkru
  • 4,178
  • 2
  • 17
  • 36
  • Thanks to help me, but this solution is giving the gravity of toast to only LEFT, RIGHT, TOP, BOTTOM, but i need toast gravity where ever i am tapping the overlay icon, Now finally i got solution.. – Vishesh Chandra May 28 '12 at 05:35