簡體   English   中英

Android - Google 地圖頂部的浮動操作按鈕

[英]Android - Floating Action Button over the top of a Google Map

當我將浮動操作按鈕放在 Google 地圖的頂部時,它會阻止我與地圖進行交互。

高度和寬度的布局是 match_parent,所以 FAB 占據了整個屏幕,但它在我的其他 Fragment(沒有谷歌地圖)上也是如此,我可以與這些 FAB 后面的視圖進行交互。 當 FAB 位於帶有 Google 地圖的 Fragment 上時,我無法與 FAB 后面的任何視圖進行交互。

我正在使用這個浮動操作按鈕: https : //github.com/Clans/FloatingActionButton

有沒有人有解決方案?

嘗試將android:focusable="false"android:clickable=false到您的 FloatingActionButton。 但是說真的,為什么要讓浮動操作按鈕占據整個屏幕?

所以我最終做的是將片段放在一個帶有 ViewPager 的活動中,並將 FAB 放在該活動的 xml 中,這允許我與 ViewPager 持有的片段中的地圖進行交互

嘗試了您的代碼,我無能為力,因為您使用了許多我沒有的可繪制對象,我建議您將此庫用於浮動操作按鈕,我正在使用相同的並且它們工作得很好。

語法是

 <com.melnykov.fab.FloatingActionButton
            android:id="@+id/buttonFloat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/abc_ic_menu_share_mtrl_alpha"
            fab:fab_colorNormal="#C2185B"
            fab:fab_colorPressed="#FF4081"
            fab:fab_colorRipple="#F06292" />

compile 'com.melnykov:floatingactionbutton:1.3.0'

在處理完 FAB 之后和渲染之前,您應該以編程方式添加這些行。

fabButton.setFocusable(false);
fabButton.setFocusableInTouchMode(false);

這個對我有用。

您需要將ToggleListener添加到您的FloatingActionMenu ,然后您可以隱藏接管屏幕的按鈕。

fabMenu.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
            @Override
            public void onMenuToggle(boolean opened) {
                if(opened){
                    fltActsettings.setVisibility(View.VISIBLE);
                    fltActnotifications.setVisibility(View.VISIBLE);
                    fltShowMenu.setVisibility(View.VISIBLE);
                    fltActCreateRequest.setVisibility(View.VISIBLE);
                    fltActHistory.setVisibility(View.VISIBLE);
                }else{
                    fltActsettings.setVisibility(View.GONE);
                    fltActnotifications.setVisibility(View.GONE);
                    fltShowMenu.setVisibility(View.GONE);
                    fltActCreateRequest.setVisibility(View.GONE);
                    fltActHistory.setVisibility(View.GONE);
                }
            }
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM