android - 无法与 PopupWindow 和 Background (GoogleMap) 交互

标签 android android-widget popupwindow google-maps-android-api-2

我有一个弹出窗口,当我单击 map 标记时会显示该窗口。 PopupWindow 允许用户更改标记的位置并选择它周围的半径。如果我将 focusable 设置为 true,我可以与 PopupWindow 交互,但不能与 map 交互。而且,如果我将 focusable 设置为 false,奇怪的是,我可以与 PopupWindow 上的 SeekBar 交互,但 Buttons 和 EditText 都没有响应,但我可以与 map 交互。

问题:如何让用户可以同时与 PopupWindow 和 map 进行交互?

        <LinearLayout android:layout_width="0dp" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" 
            android:orientation="vertical">

            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/event" 
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText android:id="@+id/markerEventNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="@string/your_event_name"
                android:inputType="text" />

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

                <TextView android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/radius"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView android:id="@+id/radiusTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </LinearLayout>

            <SeekBar android:id="@+id/radiusSeekBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp" />

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

                <Button android:id="@+id/editEventButton"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/edit_event" />

                <Button android:id="@+id/cancelMarkerWindowButton"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/close" />
            </LinearLayout>
        </LinearLayout>

        <TableLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">

            <TableRow android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:gravity="center">

                <ImageButton android:id="@+id/ImageButton03"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:src="@drawable/arrow_1" />
            </TableRow>

            <TableRow android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageButton android:id="@+id/ImageButton01"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/arrow_1"/>

                <ImageButton android:id="@+id/ImageButton02"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/arrow_1"/>
            </TableRow>

            <TableRow android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center">

                <ImageButton android:id="@+id/imageButton1"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/arrow_1" />
            </TableRow>
        </TableLayout>
    </LinearLayout>
    <View android:layout_width="match_parent"
        android:layout_height="3dp"
        android:background="@color/WhiteSmoke" />

    //Constructor
    public MarkerPopupWindow(Marker edited_event_marker,Context context)
    {   
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View markerWindowView = inflater.inflate(R.layout.event_editor_popup_window, null, false);
        markerWindowView.findViewById(R.id.cancelMarkerWindowButton);

        int height =  ViewGroup.LayoutParams.WRAP_CONTENT;
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        PopupWindow markerWindow = new PopupWindow(markerWindowView,
                width,height,
                false); //Focusable, if false window cannot be touched.
        markerWindow.setWindowLayoutMode(width, height);
        //Called these methods (commented out) attempting to fix the problem without success.
        //markerWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        //markerWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        //markerWindow.setOutsideTouchable(true);
        markerWindow.showAtLocation(findViewById(R.id.location_tab_container), Gravity.TOP, 0, 0);
    }

最佳答案

您使用弹出窗口的方式是 map 或弹出窗口都可以具有焦点,如果您希望能够在弹出窗口打开的情况下移动 map ,我认为您可能需要从 map api 获取弹出窗口,就像您点击标记时谷歌地图显示的方式一样。

有关弹出窗口(在 map api 中称为 InfoWindow)的更多信息,您可以转到 here

关于android - 无法与 PopupWindow 和 Background (GoogleMap) 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15190644/

相关文章:

java - Android 项目 - RuntimeException ,由 Null Pointer Exception 引起

android - 如何告诉 Gradle 不要在我的 .jar 依赖项中排除 .so 文件?

java - 尝试从我的 android java 应用程序调用 Web 服务时出现 android.os.NetworkOnMainThreadException 异常?

android - 为什么我在使用此代码发布图像之前看不到应用程序允许访问 facebook 照片发布的屏幕?

android - 如何设置 PopupWindow 的布局和大小

android - android PopupWindow 可以显示另一个 PopupWindow 吗?

android - 推迟 onEvent 的最佳方法?

Android onReceive 未调用

android - RTSP 安卓媒体播放器

android - 单击时弹出窗口中的错误微调器