Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在谷歌地图上显示标签_Java_Android_Android Fragments_Google Maps Api 2_Mapfragment - Fatal编程技术网

Java 在谷歌地图上显示标签

Java 在谷歌地图上显示标签,java,android,android-fragments,google-maps-api-2,mapfragment,Java,Android,Android Fragments,Google Maps Api 2,Mapfragment,我在谷歌地图上显示文本视图时遇到问题。我在onCreate方法期间以编程方式将MapFragment添加到FrameLayout中,TextView位于XML文件中。就我所见,TextView被正确显示,但MapFragment会覆盖它,并在添加到FrameLayout时隐藏TextView。我已经在这里搜索了StackOverflow,但我能找到的每一个类似主题都有一个XML静态映射片段 下面是我的代码:src/java/SearchMapFragment.java @Override pub

我在谷歌地图上显示文本视图时遇到问题。我在onCreate方法期间以编程方式将MapFragment添加到FrameLayout中,TextView位于XML文件中。就我所见,TextView被正确显示,但MapFragment会覆盖它,并在添加到FrameLayout时隐藏TextView。我已经在这里搜索了StackOverflow,但我能找到的每一个类似主题都有一个XML静态映射片段

下面是我的代码:src/java/SearchMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    ...
    mMapFragment = MapFragment.newInstance(options);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.map_layout,mMapFragment);
    fragmentTransaction.commit();
    ((TextView)rootView.findViewById(R.id.map_label)).setVisibility(View.VISIBLE);
    ...
}
和我的XML文件:res/layout/fragment\u search\u map.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/search_map_wrapper_layout"
    tools:context="com.appsolute.ParkYoo.SearchMapFragment">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/map_layout"
        android:layout_weight="100">

        <TextView style="@style/DarkBlueText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/map_label"
            android:gravity="center"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:visibility="gone"/>

    </FrameLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1">

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/search_map_frame_layout">

            <Button style="@style/WhiteText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Lancer la recherche"
                android:layout_margin="5dp"
                android:id="@+id/launch_search"
                android:background="@drawable/lancer" />

        </FrameLayout>
    </LinearLayout>
</LinearLayout>


如有任何帮助,我们将不胜感激,并提前表示感谢

我终于找到了答案。基本上,我记得在某个地方看到android上布局文件的xml架构是“背对背”的。这意味着xml布局文件越低,小部件在前面的位置就越多。因此,小部件是一个放在另一个上面的

因此,我尝试在xml文件中的FrameLayout之后放置一个TextView,但结果是相同的,可能是因为片段是在运行时添加到FrameLayout中的,所以它是最后添加的片段,并且与onCreate方法中的TextView重叠

为了解决我的问题,我对XML进行了如下修改:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/search_map_wrapper_layout"
    android:gravity=""
    tools:context="com.appsolute.ParkYoo.SearchMapFragment">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/map_layout_leave_place"
        android:layout_above="@+id/utility_linear_layout">

    </FrameLayout>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:id="@+id/leave_place_label">

    </FrameLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/utility_linear_layout"
        android:orientation="vertical"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true">

        <TextView style="@style/DarkBlueText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:id="@+id/street_leave_parking_spot"
            android:layout_marginTop="10dp"
            android:text="Rue X"/>

        <TextView style="@style/TitleText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:id="@+id/city_leave_parking_spot"
            android:paddingBottom="15dp"
            android:background="@drawable/discontinued_line"
            android:text="75009 PARIS"/>

        <Button style="@style/WhiteText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:text="Mémoriser ma place"
            android:id="@+id/remember_parking_spot"
            android:background="@drawable/lancer"
            android:layout_gravity="center_horizontal|bottom"/>

        </LinearLayout>

</RelativeLayout>
下面是它的作用:


您是否尝试在地图上创建动态覆盖文本视图?如果我知道如何创建,我会这样做的。您是否建议以编程方式添加TextView?是否尝试使用RelativeLayout而不是LinearLayout?你可以在上面定位你的文本视图。我会尝试使用相对布局,然后返回给你。在尝试使用相对布局后,结果是一样的。文本视图位于谷歌地图后面。
LabelFragment frag = LabelFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.leave_place_label,frag);
ft.commit();