如何解决如何在同一屏幕上显示地图视图和列表视图?
| 通常,我只是将活动分开,但我想显示一个屏幕,其中包含视图文本视图,列表和地图视图。我不确定该怎么做,因为我知道该活动只能扩展listview或mapview。 我有一个这样的xml文件,我们将其称为main.xml<?xml version=\"1.0\" encoding=\"utf-8\"?>
<RelativeLayout android:id=\"@+id/relativeLayout1\"
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_height=\"fill_parent\" android:layout_width=\"fill_parent\">
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\"
android:orientation=\"vertical\" android:background=\"#ffffff\">
<TextView android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:id=\"@+id/tvName\"
android:textColor=\"@color/dark\" android:text=\"Name\"></TextView>
<EditText android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\" android:id=\"@+id/etName\"></EditText>
<Button android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:id=\"@+id/btnAdd\"
android:text=\"Add location\"></Button>
<ListView android:layout_height=\"wrap_content\"
android:layout_width=\"match_parent\" android:id=\"@android:id/list\"></ListView>
</LinearLayout>
和另一个只是大地图的xml文件
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<ScrollView xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\">
<com.google.android.maps.MapView
android:id=\"@+id/mapsView\" android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\" android:clickable=\"true\"
android:apiKey=\"myapikey\" />
主要活动使用列表为第一个xml工作表充气,但是如何将地图添加到该工作表中呢?我是否嵌套一个扩展了地图活动类的类,以及如何添加视图?
这就是我的想法
public class AddLocationActivity extends ListActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setLayout(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
}
public class ShowMap extends MapActivity{
public ShowMap(){
//maybe get the map.xml and add the view somehow?
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
}
解决方法
就像mkso所评论的那样,您无需从ѭ3扩展为使用
ListView
,请参见此示例(不是最好的示例,但是我很快就能找到)。只需按需要创建布局,从ѭ5扩展,然后通过调用findViewById()
使用ѭ4。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。