Java Android-如何在谷歌地图上显示图像视图?
我有一个片段,里面有谷歌地图。我想在谷歌地图的imageview中显示一个标记,通过拖动它来选择地图上的坐标 我想要什么 但事实就是这样,在安卓设备上的应用程序上,标记是不可见的Java Android-如何在谷歌地图上显示图像视图?,java,android,xml,google-maps,android-layout,Java,Android,Xml,Google Maps,Android Layout,我有一个片段,里面有谷歌地图。我想在谷歌地图的imageview中显示一个标记,通过拖动它来选择地图上的坐标 我想要什么 但事实就是这样,在安卓设备上的应用程序上,标记是不可见的 谢谢。尝试将自定义图像添加为地图上的标记打印标记,作为具有自定义布局的自定义图像。尝试将自定义图像添加为地图上的标记打印标记,作为具有自定义布局的自定义图像。您可以使用此方法在活动或片段中创建自定义标记… 公共静态位图createCustomMarker(上下文上下文,@DrawableRes int res
谢谢。尝试将自定义图像添加为地图上的标记打印标记,作为具有自定义布局的自定义图像。尝试将自定义图像添加为地图上的标记打印标记,作为具有自定义布局的自定义图像。您可以使用此方法在活动或片段中创建自定义标记… 公共静态位图createCustomMarker(上下文上下文,@DrawableRes int resource,字符串_name){ 您可以像下面这样调用此方法:
.icon(BitmapDescriptorFactory.fromBitmap(createCustomMarker(MainActivity.this,R.drawable.marker_iv,“自定义标记”));您可以使用此方法在活动或片段中创建自定义标记… 公共静态位图createCustomMarker(上下文上下文,@DrawableRes int resource,字符串_name){ 您可以像下面这样调用此方法:
.icon(BitmapDescriptorFactory.fromBitmap(createCustomMarker(MainActivity.this,R.drawable.marker_iv,“自定义标记”));使用framelayout并将Imageview移动到mapview下方(在xml中)使用framelayout并将Imageview移动到mapview下方(在xml中)
<?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" />
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;
}