Circle drawable looks like oval on map

纵然是瞬间 提交于 2019-12-25 04:58:11

问题


Hi I am trying create circle shape on map. For that i am using ground overlay item. I tried draw circle shape with drawable xml file. First I tried in normal activity layout and it shows me perfect circle shape. same thing I tried to draw on map it looks like oval shape. My code for drawable and layout is as follows :

<?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>

and my layout file :

<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>

I tried to create ground overlay item as follows :

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);

same thing I tried for activity which shows me circle but for map it showing oval shape not circle shape. How to do this? Need Help. Thank you.


回答1:


You could simply add a Circle directly, instead of using a GroundOverlay:

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


来源:https://stackoverflow.com/questions/20795339/circle-drawable-looks-like-oval-on-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!