0

我有我的應用程序中的地圖片段,並且正如我所說,它導致渲染問題,我試圖清理/重建項目,渲染與不同的API,但它不工作,這是一個錯誤:谷歌地圖片段導致渲染錯誤在android工作室

Preview timed out while rendering the layout. 

如果我評論這一切工作正常,這裏是代碼:

<android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawerlayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


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

       <include 
        android:id="@+id/customtoolbar" 
        layout="@layout/toolbar_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"/> 

      <!-- 
        <fragment 

         android:id="@+id/map_fragment_id" 
         android:name="com.google.android.gms.maps.MapFragment" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_alignParentStart="true" 
         android:layout_below="@+id/customtoolbar" 
         tools:layout="@layout/activity_main" /> --> 


       <Button 
        android:id="@+id/main_btn" 
        android:layout_width="280dp" 
        android:layout_height="50dp" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="6dp" 
        android:background="@drawable/radius_corners_green_background" 
        android:gravity="center" 
        android:textColor="#FFF" 
        android:textSize="17sp" 
        android:text="yep"/> 

     </RelativeLayout> 

      <android.support.design.widget.NavigationView 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       app:menu="@menu/navigation_menu" 
       android:layout_gravity="start" 
       app:headerLayout="@layout/navigation_header"> 
      </android.support.design.widget.NavigationView> 

    </android.support.v4.widget.DrawerLayout> 
+0

那是因爲你的設計師預覽比你目前的API級使用更高的API級別。嘗試在build.gradle中更改它並同步您的項目。 –

回答

0

試試這個

<fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

您的活動實施OnMapReadyCallback

裏面添加的onCreate()

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 

覆蓋onMapReady()方法,該行

@Override 
public void onMapReady(GoogleMap map) { 
    // googleMap = map; 
}