我在显示我的Google地图上的TextView时遇到问题。我在onCreate方法中以编程方式在FrameLayout中添加MapFragment,并且TextView位于XML文件中。对于我所看到的,TextView已正确显示,但MapFragment会将其添加到FrameLayout中并隐藏TextView。我已经在这里搜索了StackOverflow,但是我可以找到的每个类似的主题都是使用XML中的静态MapFragment。在Google地图上显示标签
这里是我的代码: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 FIL:RES /布局/ fragment_search_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>
任何帮助将不胜感激感谢中前进!
有你尝试在地图上创建动态覆盖的TextView? – Mohit 2014-10-01 13:13:56
如果我知道如何去做,我会做到的。你是否建议以编程方式添加TextView? – user3476114 2014-10-01 13:46:23
你是否尝试用RelativeLayout代替LinearLayout?你可以在上面放置你的TextView。 – 2014-10-01 13:46:34