@@ -3,11 +3,9 @@ package com.pizzk.overlay
3
3
import android.content.Context
4
4
import android.graphics.*
5
5
import android.util.AttributeSet
6
- import android.view.LayoutInflater
7
6
import android.view.View
8
7
import android.view.ViewGroup
9
8
import androidx.annotation.ColorRes
10
- import androidx.annotation.IdRes
11
9
import androidx.constraintlayout.widget.ConstraintLayout
12
10
import androidx.constraintlayout.widget.ConstraintSet
13
11
import androidx.core.content.ContextCompat
@@ -71,9 +69,8 @@ class OverlayLayout : ConstraintLayout {
71
69
getLocationOnScreen(vXY)
72
70
val vAnchorXY = IntArray (2 )
73
71
//
74
- val lf = LayoutInflater .from(viewGroup.context)
75
72
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
77
74
// 计算宽度及位置
78
75
vAnchor.getLocationOnScreen(vAnchorXY)
79
76
rect.left = vAnchorXY[0 ] - vXY[0 ] - 0f
@@ -88,11 +85,11 @@ class OverlayLayout : ConstraintLayout {
88
85
val anchor = onFakeAnchor(e.id, rect.toRect())
89
86
// 标记层布局
90
87
val markers = overlay.markers.filter { it.anchor == e.id }
91
- markers.forEach { onLayoutMarker(lf , it, anchor) }
88
+ markers.forEach { onLayoutMarker(viewGroup.context , it, anchor) }
92
89
}
93
90
}
94
91
95
- private fun onFakeAnchor (@IdRes id : Int , rc : Rect ): View {
92
+ private fun onFakeAnchor (id : Int , rc : Rect ): View {
96
93
val v: View ? = getViewById(id)
97
94
if (null != v) return v
98
95
val view = View (context)
@@ -106,9 +103,9 @@ class OverlayLayout : ConstraintLayout {
106
103
return view
107
104
}
108
105
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()
112
109
addView(v)
113
110
val cs = ConstraintSet ()
114
111
cs.clone(this )
0 commit comments