library / org.akop.kotx.ext.view / android.view.ViewGroup

Extensions for android.view.ViewGroup

children

fun ViewGroup.children(): Iterable<View>

Returns an Iterable object for the children of a ViewGroup.

clear

fun ViewGroup.clear(): Unit

Same as ViewGroup.removeAllViews.

collapseIfEmpty

fun ViewGroup.collapseIfEmpty(): Unit

Sets receiver's visibility to View.GONE if receiver has no children; sets it to View.VISIBLE otherwise.

firstChild

fun <T : View> ViewGroup.firstChild(): T

Returns first child as type T.

firstChildOrNull

fun <T : View> ViewGroup.firstChildOrNull(): T?

Returns first child as type T if available, null if the ViewGroup has no children, or if the child isn't of the expected type.

get

operator fun ViewGroup.get(index: Int): View

Returns child view at specified index.

getOrNull

fun ViewGroup.getOrNull(index: Int): View?

Returns child view at specified index.

hideIfEmpty

fun ViewGroup.hideIfEmpty(): Unit

Sets receiver's visibility to View.INVISIBLE if receiver has no children; sets it to View.VISIBLE otherwise.

inflate

fun ViewGroup.inflate(layoutId: Int, attachToRoot: Boolean = false): View

Inflates a (child) view using LayoutInflater obtained with the view's context.

isEmpty

val ViewGroup.isEmpty: Boolean

Returns true if the ViewGroup has no children.

isNotEmpty

val ViewGroup.isNotEmpty: Boolean

Returns true if the ViewGroup has children.

minusAssign

operator fun ViewGroup.minusAssign(view: View): Unit

Removes child view from the receiver.

plusAssign

operator fun ViewGroup.plusAssign(view: View): Unit

Adds a child view to the receiver.

operator fun ViewGroup.plusAssign(views: Iterable<View>): Unit

Adds child views to the receiver, in the original order.

size

val ViewGroup.size: Int

Same as ViewGroup.getChildCount.