9

簡単なコード ブロックを使用して、infoWindow のコンテンツをカスタマイズできます。

 private GoogleMap mMap;
 mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {

            View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
            return v;

        }
    });

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="HELLO"
        android:textColor="#FF0000"/>

</LinearLayout>

ただし、これはコンテンツのみを変更し、infoWindow 自体は変更しません。それはまだ白いままで、下部に小さな影があり、黒い背景に赤い HELLO テキストが表示されます。このデフォルトの infoWindow を透明な黒い四角形に変更したいと考えています。これどうやってするの?

ここに画像の説明を入力

4

4 に答える 4

35

getInfoWindow メソッドでコードを記述する必要があります。情報ウィンドウをカスタマイズできます。例えば

@Override
public View getInfoWindow(Marker marker) {

    // Getting view from the layout file
    View v = inflater.inflate(R.layout.map_popup, null);

    TextView title = (TextView) v.findViewById(R.id.title);
    title.setText(marker.getTitle());

    TextView address = (TextView) v.findViewById(R.id.distance);
    address.setText(marker.getSnippet());

    return v;
}

@Override
public View getInfoContents(Marker arg0) {
    // TODO Auto-generated method stub
    return null;
}
于 2013-08-14T09:19:44.513 に答える