【问题标题】:Include Google Maps V2 Map in Activity with two Framelayouts在具有两个框架布局的 Activity 中包含 Google Maps V2 地图
【发布时间】:2015-01-23 20:06:56
【问题描述】:

我在我的 Android 应用程序中获得了一个带有两个 FrameLayouts 的 Activity。我想使用 googlemaps v2 在顶部框架布局中包含地图。在底部框架布局中,我想实现一个列表。每次我在地图中添加片段时,地图都会使用完整的屏幕,如果我在第二个框架布局中包含一个列表,我会收到一个空指针错误。

这是我如何在地图中包含片段的代码:

setContentView(R.layout.activity_new_tour);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
GoogleMapsFragment googleMapFragment = new GoogleMapsFragment();
ft.replace(R.id.fragment111_container,
googleMapFragment,"mapfragment");
ft.addToBackStack(null);
ft.commit();:

这是活动的布局

<FrameLayout  
      android:id="@+id/fragment111_container"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="40"
      />

    <FrameLayout
        android:id="@+id/fragment222_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="60" />

    <!-- Listview to display slider menu -->
<ListView
   android:id="@+id/list_slidermenu"
    android:layout_width="270dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/white"
    android:dividerHeight="1dp"        
    android:listSelector="@color/blue"
    android:background="@color/black"/>


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

谁能告诉我这是否可行,我该怎么做?也许有人可以给我举个例子。

【问题讨论】:

  • 问题是什么?

标签: android google-maps android-fragments google-maps-api-3


【解决方案1】:

在你的 XML 文件中,如果你想把 mapFragment 放在 frameLayout 和 ListView 的顶部,你应该把它们都放在 FrameLayout 里面。此外,您可能希望在 FrameLayout 中放置一个 RelativeLayout 或 LinearLayout,以便您可以在 ListView 上方制作 mapFragment。

示例 XML:

<FrameLayout>
   <RelativeLayout>
      <Fragment android:id="+id/mapFragment"
                ....../>
      <ListView android:id="list"
                android:layout_below="+id/mapFragment"
                ...... />
   </RelativeLayout>
</FrameLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多