Indicates whether the view is currently tracking transient state that the
app should not need to concern itself with saving and restoring, but that
the framework should take special note to preserve when possible.

LAYER_TYPE_HARDWARE

Indicates that the view has a hardware layer. A hardware layer is backed
by a hardware specific texture (generally Frame Buffer Objects or FBO on
OpenGL hardware) and causes the view to be rendered using Android's hardware
rendering pipeline, but only if hardware acceleration is turned on for the
view hierarchy. When hardware acceleration is turned off, hardware layers
behave exactly as software layers.

A hardware layer is useful to apply a specific color filter and/or
blending mode and/or translucency to a view and all its children.

A hardware layer can be used to cache a complex view tree into a
texture and reduce the complexity of drawing operations. For instance,
when animating a complex view tree with a translation, a hardware layer can
be used to render the view tree only once.

A hardware layer can also be used to increase the rendering quality when
rotation transformations are applied on a view. It can also be used to
prevent potential clipping issues when applying 3D transforms on a view.

LAYER_TYPE_SOFTWARE

Indicates that the view has a software layer. A software layer is backed
by a bitmap and causes the view to be rendered using Android's software
rendering pipeline, even if hardware acceleration is enabled.

Software layers have various usages:

When the application is not using hardware acceleration, a software layer
is useful to apply a specific color filter and/or blending mode and/or
translucency to a view and all its children.

When the application is using hardware acceleration, a software layer
is useful to render drawing primitives not supported by the hardware
accelerated pipeline. It can also be used to cache a complex view tree
into a texture and reduce the complexity of drawing operations. For instance,
when animating a complex view tree with a translation, a software layer can
be used to render the view tree only once.

Software layers should be avoided when the affected view tree updates
often. Every update will require to re-render the software layer, which can
potentially be slow (particularly when hardware acceleration is turned on
since the layer will have to be uploaded into a hardware texture after every
update.)

dispatchApplyWindowInsets

Request to apply the given window insets to this view or another view in its subtree.

This method should be called by clients wishing to apply insets corresponding to areas
obscured by window decorations or overlays. This can include the status and navigation bars,
action bars, input methods and more. New inset categories may be added in the future.
The method returns the insets provided minus any that were applied by this view or its
children.

dispatchNestedFling

This method should be used to indicate that a nested scrolling child has detected
suitable conditions for a fling. Generally this means that a touch scroll has ended with a
velocity in the direction of scrolling that meets or exceeds
the minimum fling velocity
along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of
its own content, it can use this method to delegate the fling to its nested scrolling
parent instead. The parent may optionally consume the fling or observe a child fling.

Parameters

view

View

velocityX

float: Horizontal fling velocity in pixels per second

velocityY

float: Vertical fling velocity in pixels per second

consumed

boolean: true if the child consumed the fling, false otherwise

Returns

boolean

true if the nested scrolling parent consumed or otherwise reacted to the fling

dispatchNestedPreFling

Dispatch a fling to a nested scrolling parent before it is processed by this view.

Nested pre-fling events are to nested fling events what touch intercept is to touch
and what nested pre-scroll is to nested scroll. dispatchNestedPreFling
offsets an opportunity for the parent view in a nested fling to fully consume the fling
before the child view consumes it. If this method returns true, a nested
parent view consumed the fling and this view should not scroll as a result.

For a better user experience, only one view in a nested scrolling chain should consume
the fling at a time. If a parent view consumed the fling this method will return false.
Custom view implementations should account for this in two ways:

If a custom view is paged and needs to settle to a fixed page-point, do not
call dispatchNestedPreFling; consume the fling and settle to a valid
position regardless.

If a nested parent does consume the fling, this view should not scroll at all,
even to settle back to a valid idle position.

Views should also not offer fling velocities to nested parent views along an axis
where scrolling is not currently supported; a ScrollView
should not offer a horizontal fling velocity to its parents since scrolling along that
axis is not permitted and carrying velocity along that motion does not make sense.

dispatchNestedPreScroll

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

Nested pre-scroll events are to nested scroll events what touch intercept is to touch.
dispatchNestedPreScroll offers an opportunity for the parent view in a nested
scrolling operation to consume some or all of the scroll operation before the child view
consumes it.

Parameters

view

View

dx

int: Horizontal scroll distance in pixels

dy

int: Vertical scroll distance in pixels

consumed

int: Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy.

offsetInWindow

int: Optional. If not null, on return this will contain the offset
in local view coordinates of this view from before this operation
to after it completes. View implementations may use this to adjust
expected input coordinate tracking.

int: Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy.

offsetInWindow

int: Optional. If not null, on return this will contain the offset
in local view coordinates of this view from before this operation
to after it completes. View implementations may use this to adjust
expected input coordinate tracking.

Implementations of views that support nested scrolling should call this to report
info about a scroll in progress to the current nested scrolling parent. If a nested scroll
is not currently in progress or nested scrolling is not
enabled for this view this method does nothing.

Compatible View implementations should also call
dispatchNestedPreScroll before
consuming a component of the scroll event themselves.

Parameters

view

View

dxConsumed

int: Horizontal distance in pixels consumed by this view during this scroll step

dyConsumed

int: Vertical distance in pixels consumed by this view during this scroll step

dxUnconsumed

int: Horizontal scroll distance in pixels not consumed by this view

dyUnconsumed

int: Horizontal scroll distance in pixels not consumed by this view

offsetInWindow

int: Optional. If not null, on return this will contain the offset
in local view coordinates of this view from before this operation
to after it completes. View implementations may use this to adjust
expected input coordinate tracking.

type

int: the type of input which cause this scroll event

Returns

boolean

true if the event was dispatched, false if it could not be dispatched.

int: Horizontal distance in pixels consumed by this view during this scroll step

dyConsumed

int: Vertical distance in pixels consumed by this view during this scroll step

dxUnconsumed

int: Horizontal scroll distance in pixels not consumed by this view

dyUnconsumed

int: Horizontal scroll distance in pixels not consumed by this view

offsetInWindow

int: Optional. If not null, on return this will contain the offset
in local view coordinates of this view from before this operation
to after it completes. View implementations may use this to adjust
expected input coordinate tracking.

Returns

boolean

true if the event was dispatched, false if it could not be dispatched.

getAccessibilityNodeProvider

Gets the provider for managing a virtual view hierarchy rooted at this View
and reported to AccessibilityServices
that explore the window content.

If this method returns an instance, this instance is responsible for managing
AccessibilityNodeInfoCompats describing the virtual sub-tree rooted at
this View including the one representing the View itself. Similarly the returned
instance is responsible for performing accessibility actions on any virtual
view or the root view itself.

getPaddingEnd

Returns the end padding of the specified view depending on its resolved layout direction.
If there are inset and enabled scrollbars, this value may include the space
required to display the scrollbars as well.

Parameters

view

View: The view to get padding for

Returns

int

the end padding in pixels

getPaddingStart

Returns the start padding of the specified view depending on its resolved layout direction.
If there are inset and enabled scrollbars, this value may include the space
required to display the scrollbars as well.

hasExplicitFocusable

Returns true if this view is focusable or if it contains a reachable View
for which hasExplicitFocusable() returns true.
A "reachable hasExplicitFocusable()" is a view whose parents do not block descendants focus.
Only VISIBLE views for which getFocusable() would return
FOCUSABLE are considered focusable.

This method preserves the pre-O behavior of
hasFocusable() in that only views explicitly set focusable will cause
this method to return true. A view set to FOCUSABLE_AUTO that resolves
to focusable will not.

Parameters

view

View

Returns

boolean

true if the view is focusable or if the view contains a focusable
view, false otherwise

hasOverlappingRendering

This function, intended to be overridden by specific View types, is an optimization when
alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to
an offscreen buffer and then composited into place, which can be expensive. If the view has
no overlapping rendering, the view can draw each primitive with the appropriate alpha value
directly. An example of overlapping rendering is a TextView with a background image, such as
a Button. An example of non-overlapping rendering is a TextView with no background, or an
ImageView with only the foreground image. The default implementation returns true; subclasses
should override if they have cases which can be optimized.

Parameters

view

View

Returns

boolean

true if the content in this view might overlap, false otherwise.

hasTransientState

Indicates whether the view is currently tracking transient state that the
app should not need to concern itself with saving and restoring, but that
the framework should take special note to preserve when possible.

The view contents can help an AutofillService
determine how other views can be autofilled.

For example, view containers should typically return false for performance reasons
(since the important info is provided by their children), but if its properties have relevant
information (for example, a resource id called credentials, it should return
true. On the other hand, views representing labels or editable fields should
typically return true, but in some cases they could return false
(for example, if they're part of a "Captcha" mechanism).

isNestedScrollingEnabled

If nested scrolling is enabled and this View class implementation supports it,
this view will act as a nested scrolling child view when applicable, forwarding data
about the scroll operation in progress to a compatible and cooperating nested scrolling
parent.

onApplyWindowInsets

Clients may supply an OnApplyWindowInsetsListener to a view. If one is set
it will be called during dispatch instead of this method. The listener may optionally
call this method from its own implementation if it wishes to apply the view's default
insets policy in addition to its own.

Initializes an AccessibilityEvent with information about
this View which is the event source. In other words, the source of
an accessibility event is the view whose state change triggered firing
the event.

Example: Setting the password property of an event in addition
to properties set by the super implementation:

resolveSizeAndState

Utility to reconcile a desired size and state, with constraints imposed
by a MeasureSpec. Will take the desired size, unless a different size
is imposed by the constraints. The returned value is a compound integer,
with the resolved size in the MEASURED_SIZE_MASK bits and
optionally the bit MEASURED_STATE_TOO_SMALL set if the resulting
size is smaller than the size the view wants to be.

setAccessibilityLiveRegion

Sets the live region mode for the specified view. This indicates to
accessibility services whether they should automatically notify the user
about changes to the view's content description or text, or to the
content descriptions or text of the view's children (where applicable).

For example, in a login screen with a TextView that displays an "incorrect
password" notification, that view should be marked as a live region with
mode ACCESSIBILITY_LIVE_REGION_POLITE.

setActivated

Changes the activated state of this view. A view can be activated or not.
Note that activation is not the same as selection. Selection is
a transient property, representing the view (hierarchy) the user is
currently interacting with. Activation is a longer-term state that the
user can move views in and out of.

setAlpha

This method was deprecated
in API level 26.1.0.
Use setAlpha(float) directly.

Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is
completely transparent and 1 means the view is completely opaque.

Note that setting alpha to a translucent value (0 < alpha < 1) can have significant
performance implications, especially for large views. It is best to use the alpha property
sparingly and transiently, as in the case of fading animations.

setBackground

Set the background of the view to a given Drawable, or remove the background. If the
background has padding, view's padding is set to the background's padding. However,
when a background is removed, this View's padding isn't touched. If setting the padding is
desired, please usesetPadding(int, int, int, int).

setFitsSystemWindows

Sets whether or not this view should account for system screen decorations
such as the status bar and inset its content; that is, controlling whether
the default implementation of fitSystemWindows(Rect) will be
executed. See that method for more details.

When the view content is relevant for autofill but its children aren't (for example,
a credit card expiration date represented by a custom view that overrides the proper
autofill methods and has 2 children representing the month and year), it should
be IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS.

If this view has an alpha value set to < 1.0 by calling
View#setAlpha(float), the alpha value of the layer's paint is replaced by
this view's alpha value. Calling View#setAlpha(float) is therefore
equivalent to setting a hardware layer on this view and providing a paint with
the desired alpha value.

Parameters

view

View: View to set a layer paint for

paint

Paint: The paint used to compose the layer. This argument is optional
and can be null. It is ignored when the layer type is
LAYER_TYPE_NONE

If this view has an alpha value set to < 1.0 by calling
setAlpha(float), the alpha value of the layer's paint is replaced by
this view's alpha value. Calling setAlpha(float) is therefore
equivalent to setting a hardware layer on this view and providing a paint with
the desired alpha value.

setNestedScrollingEnabled

If this property is set to true the view will be permitted to initiate nested
scrolling operations with a compatible parent view in the current hierarchy. If this
view does not implement nested scrolling this will have no effect. Disabling nested scrolling
while a nested scroll is in progress has the effect of
stopping the nested scroll.

setOverScrollMode

This method was deprecated
in API level 25.1.0.
Call setOverScrollMode(int) directly. This method will be
removed in a future release.

Set the over-scroll mode for this view. Valid over-scroll modes are
OVER_SCROLL_ALWAYS (default), OVER_SCROLL_IF_CONTENT_SCROLLS
(allow over-scrolling only if the view content is larger than the container),
or OVER_SCROLL_NEVER.
Setting the over-scroll mode of a view will have an effect only if the
view is capable of scrolling.

setPivotX

Sets the x location of the point around which the view is
rotated and scaled.
By default, the pivot point is centered on the object.
Setting this property disables this behavior and causes the view to use only the
explicitly set pivotX and pivotY values.

Parameters

view

View

value

float: The x location of the pivot point.

setPivotY

Sets the y location of the point around which the view is
rotated and scaled.
By default, the pivot point is centered on the object.
Setting this property disables this behavior and causes the view to use only the
explicitly set pivotX and pivotY values.

setX

This method was deprecated
in API level 26.1.0.
Use setX(float) directly.

Sets the visual x position of this view, in pixels. This is equivalent to setting the
translationX property to be the difference between
the x value passed in and the current left property of the view as determined
by the layout bounds.

Parameters

view

View

value

float: The visual x position of this view, in pixels.

setY

This method was deprecated
in API level 26.1.0.
Use setY(float) directly.

Sets the visual y position of this view, in pixels. This is equivalent to setting the
translationY property to be the difference between
the y value passed in and the current top property of the view as determined by the
layout bounds.

startNestedScroll

A view starting a nested scroll promises to abide by the following contract:

The view will call startNestedScroll upon initiating a scroll operation. In the case
of a touch scroll this corresponds to the initial ACTION_DOWN.
In the case of touch scrolling the nested scroll will be terminated automatically in
the same manner as requestDisallowInterceptTouchEvent(boolean).
In the event of programmatic scrolling the caller must explicitly call
stopNestedScroll(View) to indicate the end of the nested scroll.

If startNestedScroll returns true, a cooperative parent was found.
If it returns false the caller may ignore the rest of this contract until the next scroll.
Calling startNestedScroll while a nested scroll is already in progress will return true.

At each incremental step of the scroll the caller should invoke
dispatchNestedPreScroll
once it has calculated the requested scrolling delta. If it returns true the nested scrolling
parent at least partially consumed the scroll and the caller should adjust the amount it
scrolls by.