android中的一个片段中的V2片段不想膨胀

时间:2013-01-31 21:29:10

标签: android google-maps fragment

我有一个带有viewpager的操作栏。 如果我理解正确,我必须为每个选项卡创建片段,这些片段将在我的操作栏中单击。 为此,我创建了从Fragment继承的xml布局文件和类。在这些类的onCreateView中,我返回inflater.inflate(xml_layout, container, false)。 一切正常,但我的问题如下。

现在我希望其中一个片段成为包含地图V2片段的布局。

实际上我希望我的片段看起来像下面的xml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_mappart"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grey" >

<LinearLayout
    android:id="@+id/map_heading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <View
        android:background="@drawable/rectangle_shape"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="50dp" />

    <TextView 
        android:id="@+id/map_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:layout_gravity="bottom"
        android:textSize="16sp"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="2dp" />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/horizontal_layout_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:layout_marginBottom="50dp" >

    <View 
        android:background="@drawable/rectangle_shape_yellow"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="250dp" />

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

<View
    android:background="@drawable/rectangle_shape"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginLeft="175dp"
    android:layout_marginTop="-50dp" />

    </LinearLayout>

现在,当我创建一个从Fragment扩展并扩充此xml的类时,它会在xml行上给出一个错误,其中我的片段V2开始。

我想说当我从SupportMapFragment扩展并在他自己的onCreateView中返回super.onCreateView()时,一切正常,但是我对地图周围的布局没有任何控制。我希望地图嵌套到我自己的特定布局中。所以,我几乎可以确定每一个都设置为替换映射V2,但问题实际上是我无法将片段膨胀为片段。

我希望我解释得很好,非常感谢有人可以帮助我!

1 个答案:

答案 0 :(得分:0)

不幸的是,你不能嵌套片段,这是你在这里尝试做的。这本来是一个方便的功能,我可以在我自己的应用程序中使用,并且解决这个限制可能很复杂。

一个视图中的片段可能在同一父层次结构中的不同视图中实例化片段,但它无法在其自己的视图层次结构中实例化片段。

有很多方法可以做你想做的事情;你只需要考虑你的设计。