Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:04:40+00:00 2026-06-08T21:04:40+00:00

I’m using MapView.addView() to display a pop-up bubble on top of an OverlayItem marker

  • 0

I’m using MapView.addView() to display a pop-up bubble on top of an OverlayItem marker when it is tapped. Sometimes the pop-up view extends beyond the edge of the display screen because of the amount of information it contains or because the marker that was tapped is close to the map’s edge. How can I determine when the pop-up view won’t fit and then adjust the map’s position so the entire pop-up view is displayed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:04:42+00:00Added an answer on June 8, 2026 at 9:04 pm

    It’s been three months since I asked this question so I thought I would post the solution I came up with just in case anyone comes across this posting. This method is part of a class that extends MapView.

    /**
     * Repositions the map, if necessary, in order to fully display the view passed in.  Mainly used
     * by the map bubbles displayed when tapping on an overlay item marker.  It's important that the
     * view passed in has already been laidout by the system so its measurements are available.
     *
     * @param view The being displayed on the map.
     */
    private void recenter(View view) {
      Display display = windowManager.getDefaultDisplay();
    
      // Get the dimensions of the physical display screen.  These will differ based on the orientation
      // of the device.
      int displayWidth  = display.getWidth();
      int displayHeight = display.getHeight();
    
      // Get the coordinates of the top left and bottom right corners of the view.
      Point topLeft     = new Point(view.getLeft(),  view.getTop());
      Point bottomRight = new Point(view.getRight(), view.getBottom());
    
      // Will be used to convert between map coordinates and pixels.
      Projection projection = getProjection();
    
      // Get the pixel coordinates for the map's current center and use that to initialize a new point
      // object that will be used to reposition the map if necessary.
      Point mapCenter = projection.toPixels(getMapCenter(), null);
      Point newCenter = new Point(mapCenter);
    
      // Adjust the "x" coordinate if necessary.
      if (topLeft.x < 0) {
        newCenter.x += topLeft.x;
      }
      else if (bottomRight.x > displayWidth) {
        newCenter.x += bottomRight.x - displayWidth;
      }
    
      // Adjust the "y" coordinate if necessary.
      if (topLeft.y < 0) {
        newCenter.y += topLeft.y;
      }
      else if (bottomRight.y > displayHeight) {
        newCenter.y += bottomRight.y - displayHeight;
      }
    
      // Reposition the map only if the newly calculated center differs from the original.
      if (!newCenter.equals(mapCenter)) {
        getController().animateTo(projection.fromPixels(newCenter.x, newCenter.y));
      }
    }
    

    One thing that tripped me up was how to make sure the view passed in had its measurements available. I solved that by registering a listener to determine when the view had been laid out by the system like so:

    // Add a listener to determine when the layout for the "mapBubbleMsg" view has been completed.
    // This will be used to reposition the map if necessary so the newly added view is visible.
    mapBubbleMsg.getViewTreeObserver().addOnGlobalLayoutListener(mapBubbleMsgLayoutListener);
    

    And here’s the listener:

    /**
     * Listen for layout changes to the "mapBubbleMsg" view.  This will be used to reposition the map
     * if necessary so the "mapBubbleMsg" view is visibile.  The first thing this listener does is
     * unregister itself in order to prevent it from being called repeatedly each time the "mapBubbleMsg"
     * view layout changes.
     */
    ViewTreeObserver.OnGlobalLayoutListener mapBubbleMsgLayoutListener = new
    ViewTreeObserver.OnGlobalLayoutListener() {
      public void onGlobalLayout() {
        mapBubbleMsg.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        recenter(mapBubbleMsg);
      }
    };
    

    I hope this helps somebody else out there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.