2

林添加另一片段到屏幕另一片段。該屏幕已經在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> 
+0

沒有解決方法嗎?我們只是接受即使在下面的另一個片段中也可以觸摸地圖嗎? –

+0

你能提供一些與你面臨的情況有關的代碼嗎?你如何在這些不同的視圖上對觸發事件的動作偵聽器進行編碼?一個可能的問題可能是觸摸事件監聽器,如果程序無法區分輕擊/滑動事件屬於哪一層屏幕。 – mico

回答

0

所以我仍然還沒有找到一種合適的方式來解決這個問題。相反,我只是禁用所有的觸摸和點擊在地圖視圖時,另一個視圖是在地圖視圖的頂部,順便說一句工作正常。

+0

我也面臨同樣的問題。我有mapview,我想使用mapview的片段頂部,當我滾動它滾動地圖的片段。但我有片段內的按鈕?你怎麼能解決這種情況?謝謝 – salih

0

萬一它可能仍然是相關的,一路上我已經處理了這個類型的佈局(一種觀點認爲出現「之上」另一個)在下列方式使用LinearLayout代替RelativeLayout的:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <SomeView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

    <PopOutView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:visibility="gone" /> 

</LinearLayout> 

在你的情況下,地圖將是SomeView和相對佈局PopOutView。然後在代碼中,只要您希望它出現,就可以撥打popOutView.setVisibility = View.VISIBLE。它縮小了第一個視圖,而不是在頂部繪製(因此具有不同的視覺效果),但至少這樣觸摸事件應該轉到正確的視圖。

0

組片段的佈局可點擊屬性爲true。它會阻止觸摸事件向下傳播。

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#FFF" 
    android:clickable="true"> 
</FrameLayout>