林添加另一片段到屏幕另一片段。該屏幕已經在SupportMapFragment中包含了MapView,因此添加的Fragment應該位於MapView的頂部。這個新的視圖覆蓋2/3的屏幕和地圖的很大一部分,但是當我在視圖上滾動時,它滾動下面的MapView。這不是我所期望的,因爲新的視圖添加在MapView的頂部。新視圖存在包含包裝它內容的ImageView的相對佈局。所以當在imageview上滾動(它完全沒有功能)時,它會滾動MapView。任何人都可以解釋爲什麼發生這種情況,如果可能的話,給我一個解決方案?頂部OP一個MapView(SupportMapFragment)
編輯:
基本上我有一個填滿整個屏幕的MapView。此代碼設置我的地圖視圖:
public void setUpMapIfNeeded(int satelliteMode, LatLng startPoint, float zoomLevel) {
// Do a null check to confirm that we have not already instantiated the map.
if (mapView == null) {
// Try to obtain the map from the SupportMapFragment.
mapView = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview))
.getMap();
// Check if we were successful in obtaining the map.
if (mapView != null) {
setUpMap(satelliteMode, startPoint, zoomLevel);
}
}
}
private void setUpMap(int satelliteMode, LatLng startPoint, float zoomLevel) {
// more settings
}
然後,當用戶單擊某個標記時,必須在mapview頂部顯示一個片段。
public void createDetailView() {
detailView = new DetailViewFragment();
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.viewLayout, detailView).commit();
fragmentManager.executePendingTransactions();
}
這一切工作正常。顯示視圖(大約是整個屏幕的2/3),但用戶可以在滑動detailview時滾動地圖。該的DetailView用大量的文字和按鈕組成一個相對佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="45sp">
<!-- a lot of text and buttons here -->
</RelativeLayout>
沒有解決方法嗎?我們只是接受即使在下面的另一個片段中也可以觸摸地圖嗎? –
你能提供一些與你面臨的情況有關的代碼嗎?你如何在這些不同的視圖上對觸發事件的動作偵聽器進行編碼?一個可能的問題可能是觸摸事件監聽器,如果程序無法區分輕擊/滑動事件屬於哪一層屏幕。 – mico