私はSupportMapFragmentを持っており、マップタイプを変更するためにカスタムコントロールを追加する必要があります。 getView()を呼び出すと、私はNoSaveStateFramelayoutを取得し、それを直接またはその子に追加することをお勧めしません。Google Maps Android API v2のMapFragmentにカスタムコントロールを追加するにはどうすればよいですか?
地図の種類を変更するために地図上にボタンを追加するにはどうすればよいですか?
私はSupportMapFragmentを持っており、マップタイプを変更するためにカスタムコントロールを追加する必要があります。 getView()を呼び出すと、私はNoSaveStateFramelayoutを取得し、それを直接またはその子に追加することをお勧めしません。Google Maps Android API v2のMapFragmentにカスタムコントロールを追加するにはどうすればよいですか?
地図の種類を変更するために地図上にボタンを追加するにはどうすればよいですか?
私はonCreateViewをオーバーライドして、コード内でマップをカプセル化することを決定しました。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
View mapView = super.onCreateView(inflater, viewGroup, bundle);
RelativeLayout view = new RelativeLayout(getActivity());
view.addView(mapView, new RelativeLayout.LayoutParams(-1, -1));
// working with view
return view;
}
これは、必要に応じて機能します。
マップと幅と高さの相対レイアウトmatch_parentがある場合、相対レイアウトのフレームレイアウトの内側にマップを配置してみます。相対的なレイアウトで、あなたの望むすべての拡張されたコントロールを配置します。そうすれば、地図上に一番上に座ります。
そのようないくつかのこと:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/title_gray_background" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:text="@string/tasks"
android:paddingRight="3dp"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="@color/my_even_darker_gray" />
<Button
android:id="@+id/bLocateMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginRight="3dp"
android:background="@drawable/locate_me_button_selector"
android:clickable="true"
android:onClick="locateMeButtonOnClick"
android:text="@string/locate_me"
android:textColor="@color/my_white" />
</RelativeLayout>
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
の上にレイアウト追加するには、このコードを使用して、あなたの答えをありがとうしかし、最後に、私は私自身の解決策を考え出しました。 –
私は次のようでした:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--suppress AndroidDomInspection -->
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10sp"
android:layout_marginTop="10sp"
android:src="@android:drawable/ic_menu_mylocation"
/>
</RelativeLayout>
をMapFragmentのonCreateViewから返されたビューがでframeLayoutあります。ですので、別のレイアウトを追加する必要はありません(ビューの階層を縮小します)。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
FrameLayout mapView = (FrameLayout) super.onCreateView(inflater, viewGroup, bundle);
mapView.add(someView);
return view;
}
は、マップ
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mapView = super.onCreateView(inflater, container, savedInstanceState);
@SuppressLint("InflateParams")
FrameLayout view = (FrameLayout) inflater.inflate(R.layout.fragment_map, null);
view.addView(mapView, 0, new RelativeLayout.LayoutParams(-1, -1));
return view;
}
100万アップノート – brainmurphy1