效果如下:
实现方式:
1、引入三方库:
implementation 'io.github.razerdp:BasePopup:3.2.0'
2、代码实现
class NewUserGuide3Popup : BasePopupWindow {
constructor(activity: Activity) : super(activity)
constructor(context: Context) : super(context)
constructor(fragment: Fragment) : super(fragment)
private var mBinding: DialogNewUserGuide3Binding? = null
override fun onViewCreated(contentView: View) {
super.onViewCreated(contentView)
mBinding = DataBindingUtil.bind(contentView)
}
/**
* view 想要在那个控件上展示该弹窗
*/
fun show(view: View) {
if(context!=null&&!context.isFinishing){
EventHelper.onEvent(context, "guide_water_tutorial_show", "pagenum", "3")
SensorsHelper.track(SensorsHelper.BeginnersTutorialShow, "page_num", "3")
}
mBinding?.apply {
ivBg.post {
offsetX = (rlYin.x-rlYin.width*0.5).toInt()
update()
}
}
offsetY = view.height
showPopupWindow(view)
}
//GravityMode.ALIGN_TO_ANCHOR_SIDE 贴边
//此处为与传入view左对齐,上方,贴边展示
init {
setContentView(R.layout.dialog_new_user_guide3)
setPopupGravityMode(GravityMode.ALIGN_TO_ANCHOR_SIDE, GravityMode.RELATIVE_TO_ANCHOR)
popupGravity = Gravity.START or Gravity.TOP
setBackgroundColor(Color.parseColor("#99000000"))
}