[android]intent activity 不会开始如果地图包含在layout

发布时间: 2016/10/10 22:38:37
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我的类扩展 FragmentActivity ... Intent activity 将开始时地图不包括在 layout 。 但不幸的是, intent activity 如果activity_main_map包含在activity_main_nav不会启动。谁能帮我吗?

public class MainMapActivity extends FragmentActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_nav);

    setUpToolbarDrawer();
    setUpNavView();
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.add_bus) {
        Intent intent = new Intent(MainMapActivity.this, AddBusActivity.class);
        startActivity(intent);
    } else if (id == R.id.add_driver) {
        Intent intent = new Intent(MainMapActivity.this, AddDriverActivity.class);
        startActivity(intent);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

public void setUpToolbarDrawer() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawerLayout.setDrawerListener(toggle);
    toggle.syncState();
}

public void setUpNavView() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

activity_main_nav

<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_main"
    app:menu="@menu/activity_main_drawer" />

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

activity_main_map

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

解决方法 1:

我只是把里面包括的地图和 appBar LinearLayout 就像这样。

<?xml version="1.0" encoding="utf-8"?>

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

    <include xmlns:android="http://schemas.android.com/apk/res/android"
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <include
        layout="@layout/activity_main_map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

<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_main"
    app:menu="@menu/activity_main_drawer" />

赞助商