1

Is is possible to put fixed buttons (with image) on top of an android map.

I want to add buttons on top of the android map then when the user click on it, it performs something on the map.

Similar to the zoom control, but always visible.

pdiddy
  • 6,217
  • 10
  • 50
  • 111

2 Answers2

4

Put the map and the button in a relative layout. Something like:

<RelativeLayout>
  <MapView>
  ...
  </MapView>

  <Button>
  ..make its align parent top property true here
  </Button>
</RelativeLayout>

This should put the botton on top of the map and aligned to the top of the screen. And if you want to have a button with an image use ImageButton insead.

Urban
  • 2,201
  • 24
  • 52
  • but will this put the button on top of the map? like the zoom control? so map takes all the screen space but button are on top. – pdiddy Dec 02 '11 at 15:07
  • yes, it will be exactly like the zoom controls, Map will take full screen and the button will be on top. Additionally you can specify where on the map to put it, like in the code above im making the button to be aligned to the top of the screen. You can align it anywhere you want. – Urban Dec 02 '11 at 15:09
2

You're referring to depth or z-indexing when you're saying "on top of". Use FrameLayout and set MapView first then followed by Button.

<FrameLayout>
    <MapView />
    <Button .../>
</FrameLayout>

Edit I mentioned gravity which was wrong.

Related question: Placing/Overlapping(z-index) a view above another view in android

Community
  • 1
  • 1
John Giotta
  • 16,432
  • 7
  • 52
  • 82