3

I have mapview with and image in the center of it - all is inside FrameLayout. It's fullscreen. Now I'd like to have some button/buttons under this mapview and I can't figure out how to set it under it.

Also I'd like the imageview stay in the center of mapview.

How to rebuild it?

Code of main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:apiKey="---key---"
    android:clickable="true" >
</com.google.android.maps.MapView>

    <ImageView
        android:id="@+id/test_image"
        android:layout_width="50px"
        android:layout_height="50px"
        android:layout_gravity="center"
        android:src="@drawable/srodek" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</FrameLayout>

enter image description here I want this transparent button to be normal button under my mapview : ) Thanks!

pawel
  • 5,976
  • 15
  • 46
  • 68

2 Answers2

1

Now I'd like to have some button/buttons under this mapview and I can't figure out how to set it under it.

You can't use a FrameLayout as it doesn't allow the children to be placed relative to each other(it only allows them to be placed relative to the parent's edges), instead use a RelativeLayout:

<RelativeLayout fill_parent/fill_parent>

   <Button android:id="@+id/btn" wrap_conntent/wrap_content   
       android:layout_alignParentBottom="true" />

   <FrameLayout height="wrap_content" width="fill_parent" 
       android:above="@id/btn" android:alignParentTop="true">
         <MapView  fill_parent/fill_parent/>
         <ImageView wrap_content/wrap_content android:layout_gravity="center"/>
   </FrameLayout>

</RelativeLayout> 
user
  • 86,916
  • 18
  • 197
  • 190
  • Hey, thank you for interest. But the mapview is still full screen, and only thing which changed is that trasnaprent button is on the bottom of the map. – pawel Oct 03 '12 at 11:16
  • @pawel Yeap that will not work, I got carried away. It appears that the only way to make the `MapView` shorter to accommodate the `Button` below would be to use weights: http://stackoverflow.com/questions/6286055/layout-to-constrain-size-of-mapview?lq=1 – user Oct 03 '12 at 11:20
1

You can insert your current framelayout inside another relative layout.

<?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <View
        android:id="@+id/d1"
        android:layout_width="40dp"
        android:layout_height="10dp"
        android:layout_gravity="left|center_vertical|center_horizontal"
        android:padding="3dp" 
        />
    <FrameLayout
        android:id="@+id/flayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/button1"
        android:layout_below="@id/d1"
        android:orientation="vertical" >
        <com.google.android.maps.MapView
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:apiKey="--key--"
            android:clickable="true" >
        </com.google.android.maps.MapView>
        <ImageView
            android:id="@+id/test_image"
            android:layout_width="50px"
            android:layout_height="50px"
            android:layout_gravity="center"
            android:src="@drawable/ic_launcher" />
    </FrameLayout>
    <Button
        android:id="@id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" 
        android:layout_alignParentBottom="true"/>
</RelativeLayout>
Purush Pawar
  • 4,263
  • 2
  • 29
  • 37
  • Hey, thank you for interest. But the mapview is still full screen, and only thing which changed is that trasnaprent button is on the bottom of the map. – pawel Oct 03 '12 at 11:18
  • try changing layout_height of Frame Layout to wrap_content – Purush Pawar Oct 03 '12 at 11:22