28

GoogleMap V2に組み込まれているズームコントロールの位置をカスタマイズするにはどうすればよいですか?

Googleマップライブラリのバージョン1については、このトピックに関連する多くの質問があります。

MapViewにズームコントロールを配置する

MapViewで組み込みのズームコントロールを再配置するにはどうすればよいですか?

setBuiltInZoomControls(true)を使用してズームコントロールをレイアウトする方法は?

しかし、ライブラリのV2に関する質問は見つかりませんでした。

V2には方法がありません

(LinearLayout) mapView.getZoomControls();

前述の質問はすべて廃止されます。

前もって感謝します

4

4 に答える 4

39

何をしようとしているのかによっては、GoogleMap.setPadding()が役立つ場合があります(2013年9月に追加)。

map.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);

APIドキュメントから:

この方法では、マップの4つのエッジのそれぞれにパディングを設定することにより、マップ上の表示領域を定義し、エッジの周りのマップの部分が不明瞭になる可能性があることをマップに通知できます。マップ機能はパディングに適合します。たとえば、ズームコントロール、コンパス、著作権表示、Googleロゴは、定義された領域内に収まるように移動され、カメラの動きは、可視領域の中心を基準にして移動されます。

GoogleMapでのパディングの仕組みの説明も参照してください。

于 2013-12-05T21:17:59.783 に答える
26

はい、小さなハックでZoomControlMyLocationボタンの位置を変更できます。私のサンプルには、xmlレイアウトから拡張されたSupportMapFragmentがあります。

ZoomControlボタンとMyLocationボタンのIDを表示します。

ZoomControl id = 0x1
MyLocation button id = 0x2

ZoomControlの位置を更新するコード:

// Find map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);

// Find ZoomControl view
View zoomControls = mapFragment.getView().findViewById(0x1);

if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
    // ZoomControl is inside of RelativeLayout
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();

    // Align it to - parent top|left
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

    // Update margins, set to 10dp
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            getResources().getDisplayMetrics());
    params.setMargins(margin, margin, margin, margin);
}
于 2013-02-19T07:17:07.040 に答える
1

SupportMapFragmentではなくMapFragmentを使用しています。

import android.util.TypedValue;

onCreateで

    // Find map fragment

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapview);

    int ZoomControl_id = 0x1;
    int MyLocation_button_id = 0x2;

    // Find ZoomControl view
    View zoomControls = mapFragment.getView().findViewById(ZoomControl_id);

    if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
        // ZoomControl is inside of RelativeLayout
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();

        // Align it to - parent top|left
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        // Update margins, set to 10dp
        final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                getResources().getDisplayMetrics());
        params.setMargins(margin, margin, margin, margin);
    }
于 2018-01-22T23:57:30.473 に答える
0

記録のために:

ナビゲーションコントロールは0x4

したがって、合計で:

@LayoutRes final int ZOOM_CONTROL_ID = 0x1;
@LayoutRes final int MY_LOCATION_CONTROL_ID = 0x2;
@LayoutRes final int NAVIGATION_CONTROL_ID = 0x4;
于 2016-05-17T10:24:25.297 に答える