louiscad
08/23/2019, 10:07 AMadd
extension for ViewGroup
?
inline fun <V : View> ViewGroup.add(
view: V,
lp: ViewGroup.LayoutParams,
beforeChild: View? = null,
afterChild: View? = null
): V
If not, would it annoy you to see it in autocomplete? (😤 reaction is fine for that)ribesg
08/23/2019, 11:05 AMlouiscad
08/23/2019, 1:13 PMribesg
08/23/2019, 1:29 PMaddBefore
and addAfter
then. XOR parameters are not obvious to uselouiscad
08/23/2019, 3:28 PMispbox
08/24/2019, 5:32 PMlouiscad
08/25/2019, 12:28 AM@Suppress("CONFLICTING_OVERLOADS")
@JvmName("addBefore")
inline fun <V : View> ViewGroup.add(
view: V,
lp: ViewGroup.LayoutParams,
beforeChild: View
): V {
val index = indexOfChild(beforeChild).also {
check(it != -1) { "Value passed in beforeChild is not a child of the ViewGroup!" }
}
return view.also { addView(it, index, lp) }
}
@Suppress("CONFLICTING_OVERLOADS")
@JvmName("addAfter")
inline fun <V : View> ViewGroup.add(
view: V,
lp: ViewGroup.LayoutParams,
afterChild: View
): V {
val index = indexOfChild(afterChild).also {
check(it != -1) { "Value passed in beforeChild is not a child of the ViewGroup!" }
} + 1
return view.also { addView(it, index, lp) }
}