0

我一直致力于将地图 v2 集成到我的应用程序中,我成功地做到了,并且能够在设备和模拟器上可视化事物,但是当我尝试在布局中的地图下方添加一些小部件时,我无法平滑滚动并且地图会产生模糊的印象在屏幕上,当我尝试滚动嵌入地图片段时,请参阅下图

滚动前的初始图像

滚动后的图像

在上图中,我实际上应该在滚动时平滑过渡以显示两个按钮。但是我知道出了点问题,有人可以建议我一个解决方案吗?提前谢谢了

activity_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="730dp" >

        <com.facebook.widget.LoginButton
            android:id="@+id/login_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            facebook:confirm_logout="false"
            facebook:fetch_user_info="true" />

        <com.facebook.widget.ProfilePictureView
            android:id="@+id/profilePicture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:gravity="center_horizontal"
            facebook:preset_size="normal" >
        </com.facebook.widget.ProfilePictureView>

        <TextView
            android:id="@+id/greeting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/profilePicture"
            android:layout_centerHorizontal="true"
            android:textColor="#333"
            android:textSize="18sp" />

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="345dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/profilePicture"
            android:layout_marginTop="22dp"
            class="com.google.android.gms.maps.SupportMapFragment" />

        <Button
            android:id="@+id/mapClear"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="146dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/mapSet"
            android:layout_alignBottom="@+id/mapSet"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/greeting"
            android:text="Clear" />

        <Button
            android:id="@+id/mapSet"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="146dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/greeting"
            android:layout_below="@+id/map"
            android:layout_marginTop="10dp"
            android:text="Set" />

        <Button
            android:id="@+id/fuelTest"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/profilePicture"
            android:layout_below="@+id/mapSet"
            android:layout_marginTop="25dp"
            android:text="get fuel" />

        <TextView
            android:id="@+id/fuelLevel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/fuelTest"
            android:layout_alignBottom="@+id/fuelTest"
            android:layout_alignLeft="@+id/greeting"
            android:text="@string/fuellevel"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/post"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/greeting"
            android:layout_alignBottom="@+id/greeting"
            android:layout_alignParentRight="true"
            android:layout_marginRight="18dp"
            android:text="post" />

</RelativeLayout>

4

2 回答 2

2

不要在 ScrollView 中放置可滚动视图,因为它会导致优化和用户体验问题。例如:如果垂直滚动会改变地图的相机位置而不是向下滚动视图,这可能会造成混淆。如果用户必须能够与地图交互(正如您的地图视图的配置所暗示的那样),请将其放在顶部并在下面添加小部件。如果您的小部件不包含高度变化很大的元素(例如描述性文本视图),请使用垂直线性布局并将 30% 的权重分配给地图,其余的分配给小部件。根据您的小部件的高度,您仍然可以使用 ScrollView:

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

    <fragment
        android:id="@+id/map"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.7">

        <RelativeLayout
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
            <!-- put your widgets here -->
        </RelativeLayout>


    </ScrollView>


</LinearLayout>

如果您的用户不必与地图交互,您还可以通过Google 的静态地图 API检索相应的地图图块,并将其简单地显示在 ImageView 中。例子:

http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap
&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318
&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false
于 2013-09-22T12:35:59.333 回答
0

查看多地图的地图演示。

于 2013-09-20T20:17:00.387 回答