1
通常我只是分开活动,但我想显示一个屏幕,其中有一个视图文本视图,一个列表,然后是一个地图视图。我不知道该怎么做,因为我知道这个活动只能扩展listview或mapview。如何在同一屏幕上显示mapview和listview?
我有这样一个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;
}
}
}
为什么不能扩展MapActivity并使用ListView作为其成员。 – mkso
http://stackoverflow.com/a/30644926/3871524 试试这个..它非常帮助我在Listview中显示地图。 –