问题描述
我想将Showcaseview添加到android地图上的标记!? 展示库将视图作为参数。 如何从Marker获取视图?
我正在尝试这段代码
new GuideView.Builder(this)
.setTitle("Guide Title Text")
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
.setGravity(Gravity.auto) //optional
.setdismisstype(dismisstype.anywhere) //optional - default dismisstype.targetView
.setTargetView(view)
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.build()
.show();
其将视图作为setTargetView中的参数,而不是Marker Object
这是我要使用的图书馆 https://github.com/mreram/ShowCaseView
解决方法
Marker
未查看,因此您无法从中获取View
。但是无论如何,您都可以创建虚拟透明View
并以编程方式将其放置在所选标记上,然后通过setTargetView
方法将其传递到ShowCaseView库。因此,您需要围绕MapFragment
或MapView
,例如RelativeLayout
(activity_main.xml
)的根视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mapview_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="<YOUR_PACKAGE_NAME>.MainActivity">
<com.google.android.gms.maps.MapView android:id="@+id/mapview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
和虚拟透明视图布局(transparent_layout.xml
):
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="20dp" <- adjust size programmatically or set to default size of Marker
android:layout_height="30dp"
android:layout_centerInParent="true"
android:background="@android:color/transparent">
</View>
例如MainActivity
,您需要获得根布局并为虚拟透明视图充气,并且在选择标记(例如单击)时,您应该获取所选Marker
的当前屏幕坐标,并将虚拟透明视图恰好放置在其上方。对于RelativeLayout
,可以通过setLeft()
来获得x
坐标,通过setTop()
来获得y
坐标(当然,您需要根据{{ 1}}锚)。像这样的东西:
Marker
当然,这只是想法的示例,您应该针对标记大小,锚点等来改进该代码。