【Android】MapView跟其它控件一起显示

【Android】MapView和其它控件一起显示

很多朋友要实现MapView和其它控件一起显示,但android XML里面declare <MapView>就一直报InflateException。。。Inflate。。。打气。。。Exception被爆掉?? 寒~~~

国外达人终于解决此问题,竟然是用<class>来declare,寒~~~android API在干哈?!
main.xml:

xml 代码
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3. android:orientation="vertical" android:layout_width="fill_parent"  
  4. android:layout_height="fill_parent">  
  5.   
  6.         <view class="com.google.android.maps.MapView"  
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="fill_parent"  
  9.         android:layout_weight="1" />  
  10.           
  11.         <EditText android:layout_width="fill_parent"  
  12. android:layout_height="wrap_content"  
  13.     android:text="输入查询地址"  
  14.     android:selectAllOnFocus="true"/>  
  15. </LinearLayout>  


然后写个很简单的MapActivity:

java 代码
 
  1. public class GeoDemo extends MapActivity {  
  2.     @Override  
  3.     public void onCreate(Bundle icicle) {  
  4.         super.onCreate(icicle);  
  5.         setContentView(R.layout.main);  
  6.     }  
  7. }  


结果如图。终于可以自己做相关的Map控件和逻辑了,呵呵!

1 楼 larryzou 2007-11-25  
看起来不错啊【Android】MapView跟其它控件一起显示
custom的view都用declare方式,估计google觉得自己的map只是一个custom的component,而不是像button,text这种common component。以后可能会有其他map component比如yahoo,m$ live的
2 楼 anarki 2007-11-27  
必须的吧,好比咱们用ListActivity的时候也必须声明一个ListView
3 楼 anarki 2007-11-27  
为啥我的模拟器连不上网呢。。。。