【问题标题】:Android - How to show a imageView on google maps?Android - 如何在谷歌地图上显示 imageView?
【发布时间】:2019-02-20 18:17:41
【问题描述】:

我有一个片段,里面包含谷歌地图。我想在谷歌地图上的 imageview 中显示一个标记,以通过拖动它来选择地图上的坐标。

我想要什么

但就是这样,标记在 android 设备上的应用程序上是不可见的。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"

>
<ImageView
    android:id="@+id/imageView"
    android:layout_width="40dp"
    android:layout_height="70dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="125dp"
    app:srcCompat="@drawable/marker" />

<fragment
    android:id="@+id/mappin"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    class="com.google.android.gms.maps.SupportMapFragment"


   >

  </fragment>

   <Button
    android:id="@+id/ok"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mappin"
    android:layout_alignParentStart="true"
    android:layout_marginStart="0dp"
    android:layout_marginTop="2dp"
    android:text="Button" />

谢谢。

【问题讨论】:

  • 使用框架布局并将Imageview移动到mapview下方(在xml中)

标签: java android xml google-maps android-layout


【解决方案1】:

您好尝试将自定义图像添加为地图上的标记绘图标记作为具有自定义布局的自定义图像

【讨论】:

    【解决方案2】:

    您可以使用此方法在活动或片段中创建自定义标记...

    public static Bitmap createCustomMarker(Context context, @DrawableRes int resource, String _name) {

        View marker = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.custom_marker_layout, null);
    
        CircleImageView markerImage = (CircleImageView) marker.findViewById(R.id.user_dp);
        markerImage.setImageResource(resource);
        TextView txt_name = (TextView)marker.findViewById(R.id.name);
        txt_name.setText(_name);
    
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        marker.setLayoutParams(new ViewGroup.LayoutParams(52, ViewGroup.LayoutParams.WRAP_CONTENT));
        marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
        marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
        marker.buildDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        marker.draw(canvas);
    
        return bitmap;
    }
    

    你可以像下面这样调用这个方法:

    .icon(BitmapDescriptorFactory.fromBitmap(createCustomMarker(MainActivity.this, R.drawable.marker_iv, "自定义标记"))));

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      相关资源
      最近更新 更多