@@ -3,11 +3,9 @@ package com.pizzk.overlay
33import android.content.Context
44import android.graphics.*
55import android.util.AttributeSet
6- import android.view.LayoutInflater
76import android.view.View
87import android.view.ViewGroup
98import androidx.annotation.ColorRes
10- import androidx.annotation.IdRes
119import androidx.constraintlayout.widget.ConstraintLayout
1210import androidx.constraintlayout.widget.ConstraintSet
1311import androidx.core.content.ContextCompat
@@ -71,9 +69,8 @@ class OverlayLayout : ConstraintLayout {
7169 getLocationOnScreen(vXY)
7270 val vAnchorXY = IntArray (2 )
7371 //
74- val lf = LayoutInflater .from(viewGroup.context)
7572 overlay.anchors.forEach { e: Anchor ->
76- val vAnchor: View = e.find.onFind(viewGroup, e.id ) ? : return @forEach
73+ val vAnchor: View = e.find.onFind(viewGroup, e) ? : return @forEach
7774 // 计算宽度及位置
7875 vAnchor.getLocationOnScreen(vAnchorXY)
7976 rect.left = vAnchorXY[0 ] - vXY[0 ] - 0f
@@ -88,11 +85,11 @@ class OverlayLayout : ConstraintLayout {
8885 val anchor = onFakeAnchor(e.id, rect.toRect())
8986 // 标记层布局
9087 val markers = overlay.markers.filter { it.anchor == e.id }
91- markers.forEach { onLayoutMarker(lf , it, anchor) }
88+ markers.forEach { onLayoutMarker(viewGroup.context , it, anchor) }
9289 }
9390 }
9491
95- private fun onFakeAnchor (@IdRes id : Int , rc : Rect ): View {
92+ private fun onFakeAnchor (id : Int , rc : Rect ): View {
9693 val v: View ? = getViewById(id)
9794 if (null != v) return v
9895 val view = View (context)
@@ -106,9 +103,9 @@ class OverlayLayout : ConstraintLayout {
106103 return view
107104 }
108105
109- private fun onLayoutMarker (lf : LayoutInflater , marker : Marker , anchor : View ) {
110- val v: View = lf.inflate( marker.id, null )
111- if (v.id <= 0 ) v.id = marker.id + 0
106+ private fun onLayoutMarker (context : Context , marker : Marker , anchor : View ) {
107+ val v: View = marker.make.onMake(context, marker) ? : return
108+ if (v.id <= 0 ) v.id = marker.id + marker.hashCode()
112109 addView(v)
113110 val cs = ConstraintSet ()
114111 cs.clone(this )
0 commit comments