【问题标题】:Circle drawable looks like oval on map圆形可绘制在地图上看起来像椭圆形
【发布时间】:2013-12-27 05:31:56
【问题描述】:

您好,我正在尝试在地图上创建圆形。为此,我正在使用地面覆盖项目。我尝试使用可绘制的 xml 文件绘制圆形。首先我尝试了正常的活动布局,它向我展示了完美的圆形。我试图在地图上画同样的东西,它看起来像椭圆形。我的可绘制和布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

   <solid 
       android:color="#666666"/>

   <size 
       android:width="120dp"
    android:height="120dp"/>
</shape>

还有我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <RelativeLayout 
    android:id="@+id/circleLay"
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:layout_centerInParent="true"
    android:background="@drawable/circle">
    </RelativeLayout>

</RelativeLayout>

我尝试如下创建地面覆盖项目:

LatLng NEWARK = new LatLng(0, 0);
        View markerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
        GroundOverlayOptions newarkMap = new GroundOverlayOptions()
                .image(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(this, markerView)))
                .position(NEWARK, 860000f, 650000f);
GroundOverlay imageOverlay = googleMap.addGroundOverlay(newarkMap);

我为显示圆形的活动尝试了同样的事情,但对于地图,它显示椭圆形而不是圆形。这个怎么做?需要帮忙。谢谢。

【问题讨论】:

    标签: android google-maps xml-drawable overlayitem


    【解决方案1】:

    您可以直接添加Circle,而不是使用GroundOverlay

    Circle circle = googleMap.addCircle(new CircleOptions()
         .center(new LatLng(40.740234,-74.171505))
         .radius(10000)
         .strokeColor(Color.GRAY)
         .fillColor(Color.GRAY));
    

    【讨论】:

    • 我不想只添加圈子。该圆圈包含一些其他字段,也像一些图像和文本。这就是为什么我尝试使用地面布局。有没有办法在圆圈中添加图片和文字?
    • 我在Ground Overlay Options 中看到,.position 应仅使用位置和宽度参数(无高度)指定,以保持比例。
    • 是的所以我在做什么我在我的代码中使用 createBitFromview 它需要查看并返回可绘制。我正在使用的可绘制对象作为我的地面叠加层的图像。
    • 我认为你需要做的不是这个:.position(NEWARK, 860000f, 650000f); 试试这个:.position(NEWARK, 860000f);
    猜你喜欢
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2018-12-02
    相关资源
    最近更新 更多