android studio上的导航抽屉和地图活动

时间:2016-03-16 12:41:28

标签: android android-layout android-fragments

我创建了导航抽屉activity和地图activity。是否可以使用导航抽屉显示地图? 。如果您无法理解我的意思,请在 Google Play 中搜索此处地图,它们与我想要创建的内容相同。

1 个答案:

答案 0 :(得分:0)

使用此tetorial制作导航抽屉:Navigation Drawer

然后在xml中为你的地图创建一个片段:

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

(当然在相对布局内)

为您的片段添加一个类

    public class YourFragmentName extends Fragment {
        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
            Your_Parent_Activity = super.getActivity();
            //Initiate Context

Your_Fragment_Layout = (RelativeLayout)inflater.inflate(R.layout.activity_YourXmlLayout, container, false);

 map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
  return Your_Fragment_Layout;
}