Android 在自定义对话框中显示地图

Android 在自定义对话框中显示地图,android,map,Android,Map,我正在开发一个需要在对话框中显示地图的应用程序,其中包含一些细节,因为我已经制作了自定义布局并使用了地图片段,但如何编写代码,意味着我对此一无所知,也没有获得任何合适的教程或示例来在对话框中显示地图。谁能给我提供一些教程或代码。提前谢谢 这是我的custom_dialog.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk

我正在开发一个需要在对话框中显示地图的应用程序,其中包含一些细节,因为我已经制作了自定义布局并使用了地图片段,但如何编写代码,意味着我对此一无所知,也没有获得任何合适的教程或示例来在对话框中显示地图。谁能给我提供一些教程或代码。提前谢谢

这是我的custom_dialog.xml

<?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="wrap_content"
    android:background="@android:color/transparent" >

    <RelativeLayout
        android:id="@+id/relativeNavBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/pop_up_header" >

        <TextView
            android:id="@+id/EditItem_MapTxtName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:textColor="@color/white"
            android:textSize="18sp" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/relativeAutoComplete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/relativeNavBar"
        android:layout_marginTop="20dp"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/EditItem_mapTxtDistance11"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.25"
                android:text="@string/distance"
                android:textColor="@color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/EditItem_mapTxtDistance"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.75"
                android:ellipsize="end"
                android:singleLine="true"
                android:textColor="@color/greyish"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/EditItem_mapTxtAddress11"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.25"
                android:text="@string/address"
                android:textColor="@color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/EditItem_mapTxtAddress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.75"
                android:ellipsize="end"
                android:singleLine="true"
                android:textColor="@color/greyish"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/EditItem_mapTxtCity11"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.25"
                android:text="@string/city"
                android:textColor="@color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/EditItem_mapTxtCity"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.75"
                android:ellipsize="end"
                android:singleLine="true"
                android:textColor="@color/greyish"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/EditItem_mapTxtZip11"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.25"
                android:text="@string/zip"
                android:textColor="@color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/EditItem_mapTxtZip"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.75"
                android:ellipsize="end"
                android:singleLine="true"
                android:textColor="@color/greyish"
                android:textSize="14sp" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

您可以使用
对话框片段
在对话框中显示地图,该对话框将使用自定义布局在对话框中显示地图


签出

您可以使用
对话框片段
在对话框中显示地图,该对话框将使用自定义布局在对话框中显示地图


签出

转到android DialogFragments:。您将在这个android开发者博客中获得所需内容。

转到android DialogFragments:。您将在这个android开发者博客中获得所需内容。

复制并享受

            mDialogMaps = new Dialog(mContext);
            mDialogMaps.requestWindowFeature(Window.FEATURE_NO_TITLE);
            mDialogMaps.setContentView(R.layout.lay_dialog_map_location);
            mDialogMaps.setCancelable(true);

            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            Window window = mDialogMaps.getWindow();
            layoutParams.copyFrom(window.getAttributes());
            layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(layoutParams);

            TextView txtNoteMapTitle = (TextView) mDialogMaps.findViewById(R.id.txtNoteMapTitle);
            txtNoteMapTitle.setTypeface(G.fIranSansBold);

            mMapView = (MapView) mDialogMaps.findViewById(R.id.mapView);

            mMapView.onCreate(mDialogMaps.onSaveInstanceState());
            mMapView.onResume();


            mDialogMaps.show();

复制并享受

            mDialogMaps = new Dialog(mContext);
            mDialogMaps.requestWindowFeature(Window.FEATURE_NO_TITLE);
            mDialogMaps.setContentView(R.layout.lay_dialog_map_location);
            mDialogMaps.setCancelable(true);

            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            Window window = mDialogMaps.getWindow();
            layoutParams.copyFrom(window.getAttributes());
            layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(layoutParams);

            TextView txtNoteMapTitle = (TextView) mDialogMaps.findViewById(R.id.txtNoteMapTitle);
            txtNoteMapTitle.setTypeface(G.fIranSansBold);

            mMapView = (MapView) mDialogMaps.findViewById(R.id.mapView);

            mMapView.onCreate(mDialogMaps.onSaveInstanceState());
            mMapView.onResume();


            mDialogMaps.show();

看看我的答案@看看我的答案@迪拉杰