1

通常我只是将活动分开,但我想显示一个具有视图文本视图、列表和地图视图的屏幕。我不知道该怎么做,因为我知道活动只能扩展列表视图或地图视图。

我有一个这样的 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;
    }

}

}

4

1 回答 1

3

就像 mkso 评论的那样,您不需要扩展 fromListActivity来使用 a ListView,请参见this for example(不是最好的,但我可以很快找到)。只需创建您想要的布局,通过调用扩展MapActivity并使用.ListViewfindViewById()

于 2011-06-22T04:23:36.960 回答