0
的TextView我一直在試圖增加谷歌的片段下方的LinearLayout裏面一個TextView編程映射,但文中觀點似乎沒有得到補充。這裏是我的xml文件:添加以下地圖碎片動態
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/root">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:context="com.example.burhan.googlemapsdemoapp.MapsActivity" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="120dp"
android:gravity="center_horizontal"
android:id="@+id/mapLayout">
</LinearLayout>
,這裏是我的,用於將文本視圖代碼:
linearLayout = (LinearLayout) findViewById(R.id.mapLayout);
final TextView tv = new TextView(Map.this);
tv.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
tv.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
tv.setText("Some text");
tv.setGravity(Gravity.CENTER);
Log.d("View","StackTrace");
try{
linearLayout.addView(tv);
}catch (Exception e){
Log.e("MYAPP", "exception", e);
}
嘗試調用根的LinearLayout requestlayout()後您添加的TextView – MidasLefko
爲什麼try/catch塊? – egoldx
正試圖找出是否有任何例外......完全沒有挫折! @ user1779222 –