效果如下:
实现方式:
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? = nulloverride 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.heightshowPopupWindow(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.TOPsetBackgroundColor(Color.parseColor("#99000000"))}