android - 如何在同一屏幕上显示 map View 和 ListView ?

标签 android google-maps android-activity android-maps

通常我只是将 Activity 分开,但我想显示一个屏幕,其中有一个 View TextView 、一个列表,然后是一个 map View 。我不确定该怎么做,因为我知道该 Activity 只能扩展 ListView 或 map View 。

我有一个这样的 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文件,就是一张大 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" />

主要 Activity 使用列表扩充第一个 xml 工作表,但是我如何向其中添加 map ?我是否嵌套了一个扩展 map Activity 类的类以及如何添加 View ? 我是这么想的

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,参见 this for an example (不是最好的,但我能很快找到)。只需根据需要创建布局,从 MapActivity 扩展并通过调用 findViewById() 使用 ListView

关于android - 如何在同一屏幕上显示 map View 和 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6434306/

相关文章:

Android ProgressDialog 未显示

android - 从 Activity 传递资源 ID 以初始化自定义 ViewGroup

android - 安装后添加静态 intent-filter 定义

java - 我在 Retrofit 中得到奇怪的响应,协议(protocol)=http/1.1,代码=200

android - 谷歌地图 api key 不工作 v2

android - 从堆栈调用 Activity 而不是启动新实例

java - Android:GPS Geocoding onLocationChanged方法,为什么View元素会异步更新

android - Android 中的水平滚动页脚菜单

android - 设置 MapFragment 缩放限制

android - MapView ItemizedOverlay 上的 draw() 问题