2016-03-29 10 views
0

アンドロイドスタジオのデフォルトのGooglemapアクティビティの上にボタンを追加したいと思います。私はこのようにGoogleマップのフラグメントのXMLコードを変更することで、このいずれかを試してみました:デフォルトのGoogleマップアクティビティでボタンを追加

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<fragment 
    android:id="@+id/location_map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" /> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:padding="0dp" 
    android:paddingBottom="0dp" 
    android:background="#359c5e" 
    android:text="@string/go" 
    android:textColor="#ffffff" /> 

しかし、私は私のmapfragment上のボタンを取得することができません。 FragmentとViceversaの前にXMLファイルでButtonを書くことで、いろいろ試してみましたが、同じ問題に直面しています。

私の要件は、

  1. がmapfragment上のボタンを作成することです。
  2. クリックすると、カスタマイズされたマーカーが表示されます。

このタスクを達成する方法は?どんな提案も感謝しています。

+0

詳細については、2番目の要件をご記入ください。 –

+0

ボタンを地図の一部にしたい、または地図の上にボタンを配置したい場合があります。具体的にしてください。 –

+0

マップフラグメントのボタンとマップフラグメントの上のボタンは異なるのですか? – Abhinay

答えて

1

このレイアウトを使用してください。これはあなたの問題を解決することができます。 (最初の要件のために)

この地図の断片が最初にすべての画面を占有し、ボタンが画面の右上隅になりますようになります。地図が画面上にあるので、ボタンが地図上に表示され、地図の一部が表示されます。第二の要件

ため

<?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" 
android:orientation="vertical"> 

<fragment 
    android:id="@+id/location_map" 
    class="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#359c5e" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentEnd="true" 
    android:padding="8dp" 
    android:layout_margin="5dp" 
    android:text="@string/go" 
    android:textColor="#ffffff" /> 

</RelativeLayout> 

あなたはボタンのonclicklistenerを使用して、地図上のこれらのマーカーを表示することができます。

あなたのためにどのように機能したか教えてください。

+0

あなたの要件に合った答えを受け入れますか? –

関連する問題