Stay organized with collections
Save and categorize content based on your preferences.
ViewGroupOverlay
open class ViewGroupOverlay : ViewOverlay
A group overlay is an extra layer that sits on top of a ViewGroup (the "host view") which is drawn after all other content in that view (including the view group's children). Interaction with the overlay layer is done by adding and removing views and drawables.
ViewGroupOverlay is a subclass of ViewOverlay
, adding the ability to manage views for overlays on ViewGroups, in addition to the drawable support in ViewOverlay.
Summary
Public methods |
open Unit |
Adds a View to the overlay.
|
open Unit |
Removes the specified View from the overlay.
|
Public methods
add
open fun add(view: View): Unit
Adds a View
to the overlay. The bounds of the added view should be relative to the host view. Any view added to the overlay should be removed when it is no longer needed or no longer visible.
Views in the overlay are visual-only; they do not receive input events and do not participate in focus traversal. Overlay views are intended to be transient, such as might be needed by a temporary animation effect.
If the view has a parent, the view will be removed from that parent before being added to the overlay. Also, if that parent is attached in the current view hierarchy, the view will be repositioned such that it is in the same relative location inside the activity. For example, if the view's current parent lies 100 pixels to the right and 200 pixels down from the origin of the overlay's host view, then the view will be offset by (100, 200).
View
s added with this API will be drawn in the order they were added. Drawing of the overlay views will happen before drawing of any of the Drawable
s added with add(android.graphics.drawable.Drawable)
API even if a call to this API happened after the call to add(android.graphics.drawable.Drawable)
.
Passing null
parameter will result in an IllegalArgumentException
being thrown.
Parameters |
view |
View: The View to be added to the overlay. The added view will be drawn when the overlay is drawn. This value cannot be null . |
remove
open fun remove(view: View): Unit
Removes the specified View
from the overlay. Passing null
parameter will result in an IllegalArgumentException
being thrown.
Parameters |
view |
View: The View to be removed from the overlay. This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ViewGroupOverlay\n\nAdded in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nViewGroupOverlay\n================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/view/ViewGroupOverlay \"View this page in Java\") \n\n```\nopen class ViewGroupOverlay : ViewOverlay\n```\n\n|---|---|------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||\n| ↳ | [android.view.ViewOverlay](/reference/kotlin/android/view/ViewOverlay) ||\n| | ↳ | [android.view.ViewGroupOverlay](#) |\n\nA group overlay is an extra layer that sits on top of a ViewGroup (the \"host view\") which is drawn after all other content in that view (including the view group's children). Interaction with the overlay layer is done by adding and removing views and drawables.\n\nViewGroupOverlay is a subclass of [ViewOverlay](/reference/kotlin/android/view/ViewOverlay), adding the ability to manage views for overlays on ViewGroups, in addition to the drawable support in ViewOverlay.\n\nSummary\n-------\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [add](#add(android.view.View))`(`view:` `[View](/reference/kotlin/android/view/View)`)` Adds a `View` to the overlay. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [remove](#remove(android.view.View))`(`view:` `[View](/reference/kotlin/android/view/View)`)` Removes the specified `View` from the overlay. |\n\n| Inherited functions ||\n|---|---|\n| From class [ViewOverlay](/reference/kotlin/android/view/ViewOverlay) |------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [add](/reference/kotlin/android/view/ViewOverlay#add(android.graphics.drawable.Drawable))`(`drawable:` `[Drawable](../graphics/drawable/Drawable.html#)`)` Adds a [Drawable](../graphics/drawable/Drawable.html#) to the overlay. The bounds of the drawable should be relative to the host view. Any drawable added to the overlay should be removed when it is no longer needed or no longer visible. Adding an already existing [Drawable](../graphics/drawable/Drawable.html#) is a no-op. Passing `null` parameter will result in an [IllegalArgumentException](../../java/lang/IllegalArgumentException.html#) being thrown. \u003cbr /\u003e | | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [clear](/reference/kotlin/android/view/ViewOverlay#clear())`()` Removes all content from the overlay. \u003cbr /\u003e | | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [remove](/reference/kotlin/android/view/ViewOverlay#remove(android.graphics.drawable.Drawable))`(`drawable:` `[Drawable](../graphics/drawable/Drawable.html#)`)` Removes the specified [Drawable](../graphics/drawable/Drawable.html#) from the overlay. Removing a [Drawable](../graphics/drawable/Drawable.html#) that was not added with [add(android.graphics.drawable.Drawable)](/reference/kotlin/android/view/ViewOverlay#add(android.graphics.drawable.Drawable)) is a no-op. Passing `null` parameter will result in an [IllegalArgumentException](../../java/lang/IllegalArgumentException.html#) being thrown. \u003cbr /\u003e | ||\n\nPublic methods\n--------------\n\n### add\n\nAdded in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun add(view: View): Unit\n```\n\nAdds a `View` to the overlay. The bounds of the added view should be relative to the host view. Any view added to the overlay should be removed when it is no longer needed or no longer visible.\n\nViews in the overlay are visual-only; they do not receive input events and do not participate in focus traversal. Overlay views are intended to be transient, such as might be needed by a temporary animation effect.\n\nIf the view has a parent, the view will be removed from that parent before being added to the overlay. Also, if that parent is attached in the current view hierarchy, the view will be repositioned such that it is in the same relative location inside the activity. For example, if the view's current parent lies 100 pixels to the right and 200 pixels down from the origin of the overlay's host view, then the view will be offset by (100, 200).\n\n`View`s added with this API will be drawn in the order they were added. Drawing of the overlay views will happen before drawing of any of the `Drawable`s added with [add(android.graphics.drawable.Drawable)](/reference/kotlin/android/view/ViewOverlay#add(android.graphics.drawable.Drawable)) API even if a call to this API happened after the call to [add(android.graphics.drawable.Drawable)](/reference/kotlin/android/view/ViewOverlay#add(android.graphics.drawable.Drawable)).\n\nPassing `null` parameter will result in an [IllegalArgumentException](../../java/lang/IllegalArgumentException.html#) being thrown.\n\n| Parameters ||\n|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `view` | [View](/reference/kotlin/android/view/View): The `View` to be added to the overlay. The added view will be drawn when the overlay is drawn. This value cannot be `null`. |\n\n**See Also**\n\n- [#remove(View)](#remove(android.view.View))\n- [android.view.ViewOverlay#add(Drawable)](/reference/kotlin/android/view/ViewOverlay#add(android.graphics.drawable.Drawable)) \n\n### remove\n\nAdded in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun remove(view: View): Unit\n```\n\nRemoves the specified `View` from the overlay. Passing `null` parameter will result in an [IllegalArgumentException](../../java/lang/IllegalArgumentException.html#) being thrown.\n\n| Parameters ||\n|--------|----------------------------------------------------------------------------------------------------------------------|\n| `view` | [View](/reference/kotlin/android/view/View): The `View` to be removed from the overlay. This value cannot be `null`. |\n\n**See Also**\n\n- [#add(View)](#add(android.view.View))\n- [android.view.ViewOverlay#remove(Drawable)](/reference/kotlin/android/view/ViewOverlay#remove(android.graphics.drawable.Drawable))"]]