【问题标题】:Google Map V2 on Top half of the android screen and list view on the bottom half of the android screen安卓屏幕上半部分的 Google Map V2 和安卓屏幕下半部分的列表视图
【发布时间】:2013-05-21 06:37:04
【问题描述】:

我正在开发一个 Android 项目,我需要在 Android 屏幕的上半部分显示 Google Map v2,在同一 Android 屏幕的下半部分显示 ListView

以下是代码,到目前为止,我将在启动应用程序后立即启动。我已经为Google Map V2 key 正确设置了AndroidManifest.xml 文件。

public class SampleActivity extends Activity {

    @TargetApi(11)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sample);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().hide();
        }
        findViewById(R.id.sample_button).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int width = (int) TypedValue.applyDimension(
                                TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
                                .getDisplayMetrics());
                        SlideoutActivity.prepare(SampleActivity.this,
                                R.id.inner_content, width);
                        startActivity(new Intent(SampleActivity.this,
                                MenuActivity.class));
                        overridePendingTransition(0, 0);
                    }
                });
    }

}

下面是我需要修改的sample.xml file,这样我就可以在android屏幕的上半部分添加Google Map v2,在下半部分添加ListView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inner_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_android" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:paddingLeft="2dip"
        android:paddingRight="2dip"
        android:background="#bb000000">

        <Button style="@android:style/Widget.Button.Small"
            android:id="@+id/sample_button"
            android:layout_width="35dip"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dip"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:text=">" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/sample_button"
            android:layout_centerVertical="true"
            android:textSize="19sp"
            android:textColor="#ffffff"
            android:text="Facebook-like slide-out nav"/>
    </RelativeLayout>

</RelativeLayout>

谁能帮我解决这个问题?我完成了与设置 Google Map API v2 密钥相关的所有设置。我只需要插入代码即可开始在 android 屏幕的上半部分显示 google map v2,并在 android 屏幕的下半部分显示列表视图。

对此的任何帮助将不胜感激。谢谢

更新:-

这个更新的 XML 文件是否可以在 Android 屏幕的上半部分显示 Google Map v2,在 Android 屏幕的下半部分显示 ListView?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inner_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_android" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:background="#bb000000"
        android:paddingLeft="2dip"
        android:paddingRight="2dip" >

        <Button
            android:id="@+id/sample_button"
            style="@android:style/Widget.Button.Small"
            android:layout_width="35dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:text=">" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/sample_button"
            android:text="Proximity Application"
            android:textColor="#ffffff"
            android:textSize="19sp" />
    </LinearLayout>

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/mylist"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </ListView>
    </LinearLayout>

</LinearLayout>

【问题讨论】:

  • 执行此操作遇到什么问题?
  • 问题是,我无法获得正确的用户界面,以便在 Android 屏幕的上半部分显示 Google Map v2,在下半部分显示列表视图
  • 好的..请参阅 Emil Adz 发布的答案。

标签: java android google-maps-api-2


【解决方案1】:

这个布局应该在屏幕的上半部分显示一个地图,在下半部分显示一个 ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"
    android:orientation="vertical" >

     <fragment
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"
    android:orientation="vertical" >

    <ListView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/list">          
    </ListView>
</LinearLayout>

</LinearLayout>

【讨论】:

  • 我认为你应该从片段中删除这个 xmlns:map="schemas.android.com/apk/res-auto"。
  • @Emil,使用上述 XML。我在最后得到了这个例外 - XML document structures must start and end within the same entity. 知道为什么会这样吗?
  • @Raghunandan,已编辑,代码块删除了最后一个 LinearLayout 标记,关于您的问题,这是允许用户使用地图的地图命名空间:属性。如果不使用这些属性(在本例中),你是对的,这个命名空间可以被删除,但它不应该干扰。
  • @EmilAdz 我也打算这样做。
  • 这段代码帮助很大。它起到了魅力的作用。将 listview-LinearLayout 放在地图上方不会提供预期的输出。
【解决方案2】:

使用thisthis

希望对你有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    相关资源
    最近更新 更多