2016-04-28 296 views
0

我有導航抽屜的發射器活動。當我將地圖添加到該啓動器活動中時,我沒有看到任何工具欄,因此我無法控制導航抽屜。這裏怎麼我的活動現在看起來: enter image description hereAndroid抽屜導航工具欄丟失

這裏,它應該怎麼樣子(我需要這個工具欄) enter image description here

和導航抽屜應該重疊所以這裏的地圖這樣enter image description here

的我的代碼

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_map_nav); 

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.setDrawerListener(toggle); 
    toggle.syncState(); 

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
    navigationView.setNavigationItemSelectedListener(this); 

    mapView = new MapView(this); 

    MapHandler.getMapHandler().init(this, mapView); 

    addMarkers(); 
} 

,你可以看到我添加工具欄活動

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

這裏的MapHandler init方法()

mapView.getLayerManager().getLayers().add(tileRendererLayer); 
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
      ViewGroup.LayoutParams.WRAP_CONTENT); 
    activity.addContentView(mapView, params); 

的一部分,這裏是從清單文件

<activity 
     android:name=".map.MapNavActivity" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

代碼所以我做錯了嗎?

編輯我的導航活動XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_map_nav" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_map_nav" 
     app:menu="@menu/activity_map_nav_drawer" /> 

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

app_bar_map_nav.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="aplikacija.zveju.rinkodara.com.zvejuaplikacija.map.MapNavActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_map_nav" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 
+0

請,添加你的活動xml佈局。 – Majestic

+0

@Majestic我添加xml文件 – David

+0

這只是猜測,但也許你使用CoordinatorLayout與地圖?如果是這樣,AppBar將只顯示行爲附加到它 – Nexen

回答

0

我解決了這個問題,與雄偉的幫助。謝謝!我添加此代碼content_map_nav.xml

<org.mapsforge.map.android.view.MapView 
    android:id="@+id/mapView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
</org.mapsforge.map.android.view.MapView> 

和mainactivity代替本mapView = new MapView()我寫這篇文章mapView = (MapView) findViewById(R.id.mapView);,現在它的作品!

0

可能是你用的RelativeLayout或LinearLayout中更換ConstraintLayout在content_main.xml,如果你想使用的LinearLayout或RelativeLayout的你應該保持,但包裝你的佈局是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.gmail.farhadkargaran.myapplication.MainActivity" 
tools:showIn="@layout/app_bar_main"> 

<LinearLayout 

    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/main_bg" 
    android:orientation="vertical" 
    android:gravity="center" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    tools:showIn="@layout/app_bar_main"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 
</LinearLayout>