【问题标题】:Android Maps V2 unable to scroll smoothly - creates blur in emulatorAndroid Maps V2 无法平滑滚动 - 在模拟器中创建模糊
【发布时间】:2013-09-19 20:46:10
【问题描述】:

我一直致力于将地图 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>

【问题讨论】:

  • 我认为你最好不要将地图片段放在 ScrollView 中,地图本身可以被视为滚动视图,将滚动视图放在另一个滚动视图中总是会在 Android 中搞砸。跨度>
  • 好的,那么有没有其他解决方案可以解决这个问题?我的意思是如何将地图限制在盒子或框架内?

标签: android android-layout android-emulator android-maps-v2


【解决方案1】:

不要在 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's static map 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

【讨论】:

    【解决方案2】:

    查看多地图的地图演示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 2016-12-12
      • 1970-01-01
      • 2015-06-18
      • 2014-07-11
      • 1970-01-01
      相关资源
      最近更新 更多