很多朋友要实现MapView和其它控件一起显示,但android XML里面declare <MapView>就一直报InflateException。。。Inflate。。。打气。。。Exception被爆掉?? 寒~~~
国外达人终于解决此问题,竟然是用<class>来declare,寒~~~android API在干哈?!
main.xml:
xml 代码
- <?xml?version="1.0"?encoding="utf-8"?>??
- <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"??
- android:orientation="vertical"?android:layout_width="fill_parent"??
- android:layout_height="fill_parent">??
- ??
- ????????<view?class="com.google.android.maps.MapView"??
- ????????android:layout_width="fill_parent"??
- ????????android:layout_height="fill_parent"??
- ????????android:layout_weight="1"?/>??
- ??????????
- ????????<EditText?android:layout_width="fill_parent"??
- android:layout_height="wrap_content"??
- ????android:text="输入查询地址"??
- ????android:selectAllOnFocus="true"/>??
- </LinearLayout>??
然后写个很简单的MapActivity:
java 代码
- public?class?GeoDemo?extends?MapActivity?{??
- ????@Override??
- ????public?void?onCreate(Bundle?icicle)?{??
- ????????super.onCreate(icicle);??
- ????????setContentView(R.layout.main);??
- ????}??
- }??
结果如图。终于可以自己做相关的Map控件和逻辑了,呵呵!
1 楼 larryzou 2007-11-25
看起来不错啊
custom的view都用declare方式,估计google觉得自己的map只是一个custom的component,而不是像button,text这种common component。以后可能会有其他map component比如yahoo,m$ live的

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
为啥我的模拟器连不上网呢。。。。