如何显示一个图形窗口和在同一屏幕上一个ListView?图形、屏幕、窗口、在同一

2023-09-12 05:46:15 作者:闹心°

通常我只想单独的活动,但我想说明,有一个视图文本视图,列表,然后地图视图的画面。我不知道如何去这样做,因为我知道这个活动只能延长或者列表视图或图形页面。

Usually I would just seperate out the activities but I want to show a screen that has a view text views, a list, and then a map view. I'm not sure how to go about doing that because I know the activity can only extend either listview or mapview.

我有这样一个XML文件中,我们会叫它的main.xml

I have one xml file like this we'll call it the 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文件,这只是一个大图

and another xml file that is just a big map

<?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板的名单,但我怎么地图添加到这个?我做窝,它扩展了地图活动类和一些如何添加视图类? 这是我在想什么

The main activity inflates the first xml sheet with the list, but then how do I add the map to this? Do I nest a class that extends the map activity class and some how add the view? This is what I was thinking

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评论,你不需要从 ListActivity 扩展使用的ListView ,见本作的一个例子(不是最好的,但我能找到的快)。只需创建你想要的布局,从 MapActivity 扩展,并使用的ListView 致电 findViewById()

Like mkso commented, you do not need to extend from ListActivity to use a ListView, see this for an example (not the best, but what I could find quickly). Just create the layout how you want it, extend from MapActivity and use the ListView by calling findViewById().