3

我是android开发的新手,我正在开发一个应用程序,我需要使用谷歌地图来选择事件位置,我需要像弹出窗口一样显示这个地图,我看到了这篇文章:

DialogFragment 中的 MapFragment

我在帖子中列出了同样的问题,但我不明白如何做到这一点

她就是我所做的:

XML 布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddEventActivity" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Address :" />

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

            <ImageButton
                android:id="@+id/map_button"
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:adjustViewBounds="false"
                android:padding="3dp"
                android:scaleType="centerInside"
                android:src="@drawable/map_icon" />

            <EditText
                android:id="@+id/adress"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:ems="10" >
            </EditText>
        </LinearLayout>

        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="280dp"
                class="com.google.android.gms.maps.SupportMapFragment" />
        </FrameLayout>
    </LinearLayout>
</ScrollView>

在点击按钮上:

map_butt.setOnClickListener(new View.OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {

            // TODO Auto-generated method stub

            Window window = getWindow();
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            WindowManager.LayoutParams wmlp = window.getAttributes();
            wmlp.y -= 10;
            window.setAttributes(wmlp);
            gm = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
            marker = gm.addMarker(new MarkerOptions().title("Vous êtes ici").position(new LatLng(0, 0)));

        }
    });

谢谢你的帮助

4

0 回答 0