开发者

How to add buttons with mapview?

开发者 https://www.devze.com 2023-04-05 23:58 出处:网络
I have the following xml layout file , But what is appearing is only only the map, not the buttons ? hoa can I do that ?

I have the following xml layout file , But what is appearing is only only the map, not the buttons ? hoa can I do that ?

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        android:id="@+id/linearLayout1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">
        <com.google.android.maps.MapView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:apiKey="0ObBrVVNjsIA__m7D1lmsednIXg6pcDRBG-Qvfg"/>
        <LinearLayout 
            android:id="@+id/linearLayout2" 
            android:layout_height="wrap_content"
            android:weightSum="1.0"
            android:orientation="horizontal" 
            android:layout_gravity="bottom"
            android:layout_width="match_parent">
            <Button 
                android:text="Button" 
                android:id="@+id/button1"
                android:layout_weight="0.5"
                android:layout_height="wrap_content"></Button>

            <Butto开发者_Go百科n 
                android:text="Button" 
                android:id="@+id/button2" 
                android:layout_weight="0.5"
                android:layout_height="wrap_content"></Button>
        </LinearLayout>
    </LinearLayout>


I think you have 2 problems.

  1. your first child in linear layout that is map view , has fill_parent as width and height, which will occupy the entire screen the linear layout occupies which is the screen, hence you cannot see linear layout which has buttons.

  2. I think you want the buttons at the bottom of map view, if you don't then there is no problem. If yes, then you might want to change the orientation of parent linear layout to vertical because the default orientation is horizontal.

HTH.


Try this code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
 android:layout_height="match_parent">
<com.google.android.maps.MapView android:id="@+id/google_maps"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="@string/maps_key"/>
<Button android:id="@+id/googlemaps_select_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Select"/>

Also, you should learn more map view in android developer site. Link1

You can follow also this link: via github

0

精彩评论

暂无评论...
验证码 换一张
取 消