2014-01-17 90 views
1

我已經集成了新的谷歌地圖api v2片段在視圖尋呼機。當我從地圖選項卡(街道視圖屏幕)移動到第二個選項卡(客戶端詳細信息)時,顯示的黑色視圖將數據擴展爲片段。任何人都知道解決方案。ViewPager與谷歌地圖API v2變黑

截圖:

enter image description here

代碼:

ListingStreetViewFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 



     View inflatedView = inflater.inflate(R.layout.map_view, container, false); 


     try { 
      MapsInitializer.initialize(getActivity()); 
     } catch (GooglePlayServicesNotAvailableException e) { 
      // TODO handle this situation 
     } 

     markers = new Hashtable<String, String>(); 

     mMapView = (MapView) inflatedView.findViewById(R.id.map); 
     mMapView.onCreate(mBundle); 
     mMapView.onResume(); 
     setUpMapIfNeeded(inflatedView); 

     return inflatedView; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mBundle = savedInstanceState; 
    } 

    // mapping between map object with xml layout. 
    private void setUpMapIfNeeded(View inflatedView) { 
     if (mMap == null) { 
      mMap = ((MapView) inflatedView.findViewById(R.id.map)).getMap(); 
      if (mMap != null) { 
       mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); 
       setUpMap(); 

      } 
     } 
    } 

    //set location on map and show marker on random location 
    private void setUpMap() { 
      // random latitude and logitude 

      // Adding a marker 
      MarkerOptions marker = new MarkerOptions().position(
        new LatLng(53.558, 9.927)) 
        .title("Hello Maps "); 

      marker.snippet("dinet"); 



      // changing marker color 

       marker.icon(BitmapDescriptorFactory 
         .defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); 


      mMap.addMarker(marker); 

      // Move the camera to last position with a zoom level 
       CameraPosition cameraPosition = new CameraPosition.Builder() 
         .target(new LatLng(53.558, 
           9.927)).zoom(16).build(); 

       mMap.animateCamera(CameraUpdateFactory 
         .newCameraPosition(cameraPosition)); 
     } 



    @Override 
    public void onResume() { 

     if (null != mMapView) 
      mMapView.onResume(); 
     super.onResume(); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     if (null != mMapView) 
      mMapView.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     if (null != mMapView) 
      mMapView.onDestroy(); 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 
     if (null != mMapView) 
      mMapView.onSaveInstanceState(outState); 
    } 

    @Override 
    public void onLowMemory() { 
     super.onLowMemory(); 
     if (null != mMapView) 
      mMapView.onLowMemory(); 
    } 

ListingClientDetailFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

    View rootView = inflater.inflate(R.layout.client_detail, container, false); 

    initUi(rootView); 
    idval = ListingListFragment.cid; 
    System.out.println("SET: " + idval); 
    setValues(); 

    return rootView; 
} 


protected void initUi(View v){ 
    db = new Databasehelper(getActivity()); 

    cDetail = new HashMap<String, String>(); 

    tvName = (TextView)v.findViewById(R.id.tvName); 
    tvType = (TextView)v.findViewById(R.id.tvType); 
    tvStatus = (TextView)v.findViewById(R.id.tvStatus); 
    tvEmail = (TextView)v.findViewById(R.id.tvEmail); 
    tvPhone = (TextView)v.findViewById(R.id.tvPhone); 

    ivCall = (ImageView)v.findViewById(R.id.ivCall); 
    ivMsg = (ImageView)v.findViewById(R.id.ivMsg); 

} 

//get data from database and set into controls. 
protected void setValues(){ 

    cDetail = db.getClientDetail(idval); 
    tvName.setText(cDetail.get("name")); 
    tvType.setText(cDetail.get("type")); 
    tvStatus.setText(cDetail.get("status")); 
    tvEmail.setText(cDetail.get("email")); 
    tvPhone.setText(cDetail.get("phone")); 

} 

並且logcat中沒有錯誤顯示。所以,我不能從那裏追蹤它。

+0

哪裏是你的代碼? – GrIsHu

+0

請添加一些代碼或查看日誌貓,這可能是因爲api密鑰的身份驗證錯誤。 –

+0

@GrIsHu現在檢查它.. – Riser

回答

1

最後,我解決我的問題與添加以下代碼ListingStreetViewFragment.java文件後inflaterView

FrameLayout frameLayout = new FrameLayout(getActivity()); 
      frameLayout.setBackgroundColor(
       getResources().getColor(android.R.color.transparent)); 
      ((ViewGroup) inflatedView).addView(frameLayout, 
       new ViewGroup.LayoutParams(
        LayoutParams.FILL_PARENT, 
        LayoutParams.FILL_PARENT 
       ) 
      ); 
1

我曾經在一段時間(四至五個月,我相信)面臨類似的問題。我有一個從屏幕左側打開的滑動菜單,以及一個帶有地圖的片段。當地圖顯示時,我打開菜單,實際地圖滑向右側,但菜單覆蓋了一層黑色覆蓋層,該覆蓋層顯然在某處被地圖留下。

我想我已經解決了這個問題,這要感謝Stack Overflow問題的一些開明答案,但我再也找不到它了。雖然我不確定。也許這是對Android bug報告的一些評論。出於各種原因,我也丟失了存儲代碼的存儲庫的歷史記錄:我試圖通過記憶來重建解決方案,因此我不會打賭它會指出答案 - 也許這只是對您精確搜索的暗示可以讓自己更接近比我更多的消息來源。

但是,這裏是:我認爲它是在佈局方面解決的。 IIRC的訣竅是在地圖上添加一個透明背景的視圖。我已經在地圖上覆蓋了一層視圖,所以我只需要改變背景顏色。生成的XML文件是沿着這些路線的東西:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/map_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/transparent"> 

     <ImageView 
      android:id="@+id/menu_button" 
      android:layout_width="@dimen/menu_button_side" 
      android:layout_height="@dimen/menu_button_side" 
      android:src="@drawable/red_menu_button" 
      android:scaleType="centerCrop" /> 

    </RelativeLayout> 

</FrameLayout> 

罪魁禍首是用來渲染圖,它是黑色的默認,或一些東西的Open GL視圖的背景。我相信這確實是一個Android bug報告。因此,請嘗試在地圖上覆蓋佈局或透明背景的視圖,然後查看是否有效。就我而言,不祥的黑色封面消失了,但在菜單的滑動動畫中,它仍然清晰可見。無論如何,我認爲只是一個小故障,並對結果感到滿意。我希望這有助於某種方式。

+0

我解決了它..檢查我的答案.. – Riser

+0

@Segi ...這是我建議的XML的Java等價物。很高興有幫助。 –