Android地图显示内存不足错误

时间:2013-04-22 08:02:32

标签: android google-maps

我在我的Android应用程序中使用谷歌地图。我在xml文件中创建了一个 mapview 它工作正常但是当我把mapview放在 scrollview 时它显示 OutOfMemoryError 并崩溃。

这是我的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"
    android:background="@drawable/bg" >

    <RelativeLayout
        android:id="@+id/main_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:id="@+id/header_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/share_header" >

            <Button
                android:id="@+id/back_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@drawable/back" />

            <TextView
                android:id="@+id/header_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textStyle="bold" />

            <Button
                android:id="@+id/post_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:background="@drawable/post" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/share_leave_note_layout"
            android:layout_width="wrap_content"
            android:layout_height="150dip"
            android:layout_below="@+id/header_layout"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="5dip" >

            <ImageView
                android:id="@+id/sharer_img"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:background="@drawable/img_box" />

            <RelativeLayout
                android:id="@+id/leave_note_layout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/sharer_img"
                android:background="@drawable/comment_left_arrow_extra_big" >

                <EditText
                    android:id="@+id/leave_note_edt"
                    android:layout_width="170dip"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dip"
                    android:layout_marginRight="15dip"
                    android:layout_marginTop="10dip"
                    android:background="@null"
                    android:hint="@string/laeve_a_note_text" />

                <ImageView
                    android:id="@+id/captured_img"
                    android:layout_width="40dip"
                    android:layout_height="40dip"
                    android:layout_margin="10dip"
                    android:layout_toRightOf="@+id/leave_note_edt"
                    android:background="@drawable/img_box" />
            </RelativeLayout>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/iamat_and_with_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/share_leave_note_layout"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="5dip"
            android:gravity="center_vertical" >

            <Button
                android:id="@+id/web_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/web" />

            <Button
                android:id="@+id/iam_at_btn"
                android:layout_width="90dip"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/web_btn"
                android:background="@drawable/i_m_at" />

            <Button
                android:id="@+id/contact_logo_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/iam_at_btn"
                android:background="@drawable/contact_group" />

            <Button
                android:id="@+id/iam_with_btn"
                android:layout_width="90dip"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/contact_logo_btn"
                android:background="@drawable/i_m_with" />
        </RelativeLayout>

        <FrameLayout
            android:id="@+id/map_contact_layout"
            android:layout_width="150dip"
            android:layout_height="150dip"
            android:layout_below="@+id/iamat_and_with_layout"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="5dip"
            android:background="@drawable/rectangle_img"
            android:gravity="center_vertical" >

            <com.google.android.maps.MapView
                android:id="@+id/mapView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:apiKey="0_oThqu6ib8WYroWAckbRjYAkaoeMUX-52diovQ"
                android:clickable="true"
                android:enabled="true" />
        </FrameLayout>

        <RelativeLayout
            android:id="@+id/contact_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iamat_and_with_layout"
            android:layout_toRightOf="@+id/map_contact_layout"
            android:gravity="center_vertical" >

            <ImageView
                android:id="@+id/contact_img1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:background="@drawable/square" />

            <ImageView
                android:id="@+id/contact_img2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:layout_toRightOf="@+id/contact_img1"
                android:background="@drawable/square" />

            <ImageView
                android:id="@+id/contact_img3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/contact_img1"
                android:layout_margin="5dip"
                android:background="@drawable/square" />

            <ImageView
                android:id="@+id/contact_img4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/contact_img2"
                android:layout_margin="5dip"
                android:layout_toRightOf="@+id/contact_img3"
                android:background="@drawable/square" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/fb_twitter_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/contact_layout"
            android:layout_marginRight="5dip"
            android:background="@null" >

            <ImageView
                android:id="@+id/fb_fade_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:background="@drawable/fb_fade" />

            <ImageView
                android:id="@+id/twitter_fade_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:layout_toRightOf="@+id/fb_fade_icon"
                android:background="@drawable/twitter_fade" />
        </RelativeLayout>
    </RelativeLayout>

</ScrollView>

1 个答案:

答案 0 :(得分:1)

试试这个。

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

    <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">

        <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">

            <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content">

                <view android:layout_width="100dip" android:layout_height="90dip" class="com.google.android.maps.MapView"
                    android:apiKey="0_oThqu6ib8WYroWAckbRjYAkaoeMUX-52diovQ" android:clickable="true" />

            </FrameLayout>

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

PS:最新地图版本为Google Maps Android API v2。尝试使用它。这是一个很好的tutorial

相关问题