百度地圖api - Android百度地圖SDK,MapView上層按鈕可見卻不可觸,怎么解決?
問題描述
Android 布局中,我在百度地圖的地圖層上層(頂層)添加一個按鈕。但是添加后,按鈕可以被看見,卻觸摸不到——觸摸后還是由按鈕下面的地圖層在響應(yīng),似乎有一層透明的“地圖觸摸層”蓋住了按鈕。
我嘗試了兩種布局,效果都如上所述。其中的TextureMapView換作MapView也無濟(jì)于事:
<RelativeLayout> <android.support.design.widget.FloatingActionButton/> <com.baidu.mapapi.map.TextureMapView/></RelativeLayout>
<RelativeLayout> <com.baidu.mapapi.map.TextureMapView/> <android.support.design.widget.FloatingActionButton/></RelativeLayout>
不光是這個按鈕,我另一個BottomSheet視覺上蓋住百度地圖的時候,觸覺上仍然是地圖在頂層。
請問有什么解決辦法?謝謝。
UPD:
我發(fā)現(xiàn)如果把同一個位置的 FAB 改成普通 button 的話,button 就可以被正常點(diǎn)擊。這就讓我更疑惑了。所以補(bǔ)充上我的 xml 片段:
<RelativeLayout android:layout_width='match_parent' android:layout_height='0dp' android:layout_weight='1'> <com.baidu.mapapi.map.TextureMapViewandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:clickable='true'/> <android.support.design.widget.FloatingActionButtonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:src='http://www.aoyou183.cn/wenda/@drawable/ic_gps_fixed_black_24dp'android:layout_margin='@dimen/fab_margin'android:layout_alignParentBottom='true'android:layout_alignParentRight='true'android:layout_alignParentEnd='true'/></RelativeLayout>
問題解答
回答1:已經(jīng)用非常簡單的辦法解決:
給 FAB 添加android:clickable='true'。
雖然不知道為什么這句必須被寫上。
回答2:把你的FAB和BottomSheet放到MapView的后面。
回答3:之前也遇到過,事件分發(fā)有問題。你設(shè)置 TextureMapView的 android:clickable='true'試試
