android - 在android中的 map 中创建标记标题栏的自定义形状

标签 android google-maps

我正在使用下面的代码,它给出了一个默认的矩形 shape。我想更改 title barshape,如在图像中

enter image description here

CameraPosition cameraPos = new CameraPosition.Builder()
                    .target(ll)
                    .zoom(18).bearing(300).tilt(45).build();
         googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), null);

            if(racecourseroadmarker!=null)
                racecourseroadmarker.remove();
            racecourseroadmarker = googleMap.addMarker(new MarkerOptions()
                    .position(new LatLng(ll.latitude, ll
                            .longitude)).anchor(0.5f, 0.5f).draggable(true)
                    .title(getIntent().getStringExtra("busno")).snippet(location)
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.bus)));

            onMarkerDragStart(racecourseroadmarker);
            onMarkerDrag(racecourseroadmarker);
            racecourseroadmarker.showInfoWindow();

最佳答案

尝试使用此代码,它将帮助您在谷歌地图标记 fragment 或您可以声明的标题中创建自定义 View

View ll; 
ll = getActivity().getLayoutInflater().inflate(R.layout.markerpopup, null);
tviNamePopup = (TextView) ll.findViewById(R.id.tviNamePopup);

    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker markerss) {
            // TODO Auto-generated method stub

            String title = markerss.getTitle();
            tviNamePopup.setText(title);
            return null;
        }

        @Override
        public View getInfoContents(Marker markerss) {
            // TODO Auto-generated method stub

            // do something here

            return ll;
        }
    });

    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLngs));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(2));

布局是:markerpopup.xml

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

   <TextView
    android:id="@+id/tviNamePopup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:textColor="#0000FF" />

</LinearLayout>

关于android - 在android中的 map 中创建标记标题栏的自定义形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34060170/

相关文章:

java - 在 Google map v2 中更改相机位置后无法缩放 map

android - CWAC 更新程序问题与通知

IOS 将 2 个 GMSMarkers 之间的箭头线绘制到 Google map 中

javascript - TypeError : google. 映射。标记不是构造函数

javascript - 谷歌地图 API 无法加载 map 图 block

使用 Phonegap/Cordova 收听声音和记录音量的 Android 应用程序

android - android 中 shapes.xml 中的多个形状

android - 如何让 Eclipse 自动建议方法?

ios - 通过 Google map 或 Apple map (iOS) 使用自定义路线

javascript - 如何使用 JS 或 PHP 使用 Google Map URL 获取(多边形)区域的 KML 或 JSON 数据