public class View extends Object implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource
This class represents the basic building block for user interface components. A View
occupies a rectangular area on the screen and is responsible for drawing and
event handling. View is the base class for widgets, which are
used to create interactive UI components (buttons, text fields, etc.). The
ViewGroup
subclass is the base class for layouts, which
are invisible containers that hold other Views (or other ViewGroups) and define
their layout properties.
For information about using this class to develop your application's user interface, read the User Interface developer guide.
All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content.
Once you have created a tree of views, there are typically a few types of common operations you may wish to perform:
TextView
. The available properties and the methods
that set them will vary among the different subclasses of views. Note that
properties that are known at build time can be set in the XML layout
files.requestFocus()
.setOnFocusChangeListener(android.view.View.OnFocusChangeListener)
.
Other view subclasses offer more specialized listeners. For example, a Button
exposes a listener to notify clients when the button is clicked.setVisibility(int)
.
Note: The Android framework is responsible for measuring, laying out and
drawing views. You should not call methods that perform these actions on
views yourself unless you are actually implementing a
ViewGroup
.
To implement a custom view, you will usually begin by providing overrides for
some of the standard methods that the framework calls on all views. You do
not need to override all of these methods. In fact, you can start by just
overriding onDraw(android.graphics.Canvas)
.
Category | Methods | Description |
---|---|---|
Creation | Constructors | There is a form of the constructor that are called when the view is created from code and a form that is called when the view is inflated from a layout file. The second form should parse and apply any attributes defined in the layout file. |
|
Called after a view and all of its children has been inflated from XML. | |
Layout |
|
Called to determine the size requirements for this view and all of its children. |
|
Called when this view should assign a size and position to all of its children. | |
|
Called when the size of this view has changed. | |
Drawing |
|
Called when the view should render its content. |
Event processing |
|
Called when a new hardware key event occurs. |
|
Called when a hardware key up event occurs. | |
|
Called when a trackball motion event occurs. | |
|
Called when a touch screen motion event occurs. | |
Focus |
|
Called when the view gains or loses focus. |
|
Called when the window containing the view gains or loses focus. | |
Attaching |
|
Called when the view is attached to a window. |
|
Called when the view is detached from its window. | |
|
Called when the visibility of the window containing the view has changed. |
<Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/my_button_text"/>
Button myButton = (Button) findViewById(R.id.my_button);
View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.
The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.
It is possible to retrieve the location of a view by invoking the methods
getLeft()
and getTop()
. The former returns the left, or X,
coordinate of the rectangle representing the view. The latter returns the
top, or Y, coordinate of the rectangle representing the view. These methods
both return the location of the view relative to its parent. For instance,
when getLeft() returns 20, that means the view is located 20 pixels to the
right of the left edge of its direct parent.
In addition, several convenience methods are offered to avoid unnecessary
computations, namely getRight()
and getBottom()
.
These methods return the coordinates of the right and bottom edges of the
rectangle representing the view. For instance, calling getRight()
is similar to the following computation: getLeft() + getWidth()
(see Size for more information about the width.)
The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.
The first pair is known as measured width and
measured height. These dimensions define how big a view wants to be
within its parent (see Layout for more details.) The
measured dimensions can be obtained by calling getMeasuredWidth()
and getMeasuredHeight()
.
The second pair is simply known as width and height, or
sometimes drawing width and drawing height. These
dimensions define the actual size of the view on screen, at drawing time and
after layout. These values may, but do not have to, be different from the
measured width and height. The width and height can be obtained by calling
getWidth()
and getHeight()
.
To measure its dimensions, a view takes into account its padding. The padding
is expressed in pixels for the left, top, right and bottom parts of the view.
Padding can be used to offset the content of the view by a specific amount of
pixels. For instance, a left padding of 2 will push the view's content by
2 pixels to the right of the left edge. Padding can be set using the
setPadding(int, int, int, int)
or setPaddingRelative(int, int, int, int)
method and queried by calling getPaddingLeft()
, getPaddingTop()
,
getPaddingRight()
, getPaddingBottom()
, getPaddingStart()
,
getPaddingEnd()
.
Even though a view can define a padding, it does not provide any support for
margins. However, view groups provide such a support. Refer to
ViewGroup
and
ViewGroup.MarginLayoutParams
for further information.
Layout is a two pass process: a measure pass and a layout pass. The measuring
pass is implemented in measure(int, int)
and is a top-down traversal
of the view tree. Each view pushes dimension specifications down the tree
during the recursion. At the end of the measure pass, every view has stored
its measurements. The second pass happens in
layout(int,int,int,int)
and is also top-down. During
this pass each parent is responsible for positioning all of its children
using the sizes computed in the measure pass.
When a view's measure() method returns, its getMeasuredWidth()
and
getMeasuredHeight()
values must be set, along with those for all of
that view's descendants. A view's measured width and measured height values
must respect the constraints imposed by the view's parents. This guarantees
that at the end of the measure pass, all parents accept all of their
children's measurements. A parent view may call measure() more than once on
its children. For example, the parent may measure each child once with
unspecified dimensions to find out how big they want to be, then call
measure() on them again with actual numbers if the sum of all the children's
unconstrained sizes is too big or too small.
The measure pass uses two classes to communicate dimensions. The
View.MeasureSpec
class is used by views to tell their parents how they
want to be measured and positioned. The base LayoutParams class just
describes how big the view wants to be for both width and height. For each
dimension, it can specify one of:
MeasureSpecs are used to push requirements down the tree from parent to child. A MeasureSpec can be in one of three modes:
To initiate a layout, call requestLayout()
. This method is typically
called by a view on itself when it believes that is can no longer fit within
its current bounds.
Drawing is handled by walking the tree and recording the drawing commands of any View that needs to update. After this, the drawing commands of the entire tree are issued to screen, clipped to the newly damaged area.
The tree is largely recorded and drawn in order, with parents drawn before
(i.e., behind) their children, with siblings drawn in the order they appear
in the tree. If you set a background drawable for a View, then the View will
draw it before calling back to its onDraw()
method. The child
drawing order can be overridden with
custom child drawing order
in a ViewGroup, and with setZ(float)
custom Z values} set on Views.
To force a view to draw, call invalidate()
.
The basic cycle of a view is as follows:
requestLayout()
.invalidate()
.requestLayout()
or invalidate()
were called,
the framework will take care of measuring, laying out, and drawing the tree
as appropriate.Note: The entire view tree is single threaded. You must always be on
the UI thread when calling any method on any view.
If you are doing work on other threads and want to update the state of a view
from that thread, you should use a Handler
.
The framework will handle routine focus movement in response to user input.
This includes changing the focus as views are removed or hidden, or as new
views become available. Views indicate their willingness to take focus
through the isFocusable()
method. To change whether a view can take
focus, call setFocusable(boolean)
. When in touch mode (see notes below)
views indicate whether they still would like focus via isFocusableInTouchMode()
and can change this via setFocusableInTouchMode(boolean)
.
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. In these situations, you can provide explicit overrides by using these XML attributes in the layout file:
nextFocusDown nextFocusLeft nextFocusRight nextFocusUp
To get a particular view to take focus, call requestFocus()
.
When a user is navigating a user interface via directional keys such as a D-pad, it is necessary to give focus to actionable items such as buttons so the user can see what will take input. If the device has touch capabilities, however, and the user begins interacting with the interface by touching it, it is no longer necessary to always highlight, or give focus to, a particular view. This motivates a mode for interaction named 'touch mode'.
For a touch capable device, once the user touches the screen, the device
will enter touch mode. From this point onward, only views for which
isFocusableInTouchMode()
is true will be focusable, such as text editing widgets.
Other views that are touchable, like buttons, will not take focus when touched; they will
only fire the on click listeners.
Any time a user hits a directional key, such as a D-pad direction, the view device will exit touch mode, and find a view to take focus, so that the user may resume interacting with the user interface without touching the screen again.
The touch mode state is maintained across Activity
s. Call
isInTouchMode()
to see whether the device is currently in touch mode.
The framework provides basic support for views that wish to internally
scroll their content. This includes keeping track of the X and Y scroll
offset as well as mechanisms for drawing scrollbars. See
scrollBy(int, int)
, scrollTo(int, int)
, and
awakenScrollBars()
for more details.
Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.
Tags may be specified with character sequence values in layout XML as either
a single tag using the android:tag
attribute or multiple tags using the <tag>
child element:
<View ... android:tag="@string/mytag_value" /> <View ...> <tag android:id="@+id/mytag" android:value="@string/mytag_value" /> </View>
Tags may also be specified with arbitrary objects from code using
setTag(Object)
or setTag(int, Object)
.
By default, Views are created using the theme of the Context object supplied
to their constructor; however, a different theme may be specified by using
the android:theme
attribute in layout
XML or by passing a ContextThemeWrapper
to the constructor from
code.
When the android:theme
attribute is
used in XML, the specified theme is applied on top of the inflation
context's theme (see LayoutInflater
) and used for the view itself as
well as any child elements.
In the following example, both views will be created using the Material dark
color scheme; however, because an overlay theme is used which only defines a
subset of attributes, the value of
android:colorAccent
defined on
the inflation context's theme (e.g. the Activity theme) will be preserved.
<LinearLayout ... android:theme="@android:theme/ThemeOverlay.Material.Dark"> <View ...> </LinearLayout>
The View class exposes an ALPHA
property, as well as several transform-related
properties, such as TRANSLATION_X
and TRANSLATION_Y
. These properties are
available both in the Property
form as well as in similarly-named setter/getter
methods (such as setAlpha(float)
for ALPHA
). These properties can
be used to set persistent state associated with these rendering-related properties on the view.
The properties and methods can also be used in conjunction with
Animator
-based animations, described more in the
Animation section.
Starting with Android 3.0, the preferred way of animating views is to use the
android.animation
package APIs. These Animator
-based
classes change actual properties of the View object, such as alpha
and
translationX
. This behavior is contrasted to that of the pre-3.0
Animation
-based classes, which instead animate only
how the view is drawn on the display. In particular, the ViewPropertyAnimator
class
makes animating these View properties particularly easy and efficient.
Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered.
You can attach an Animation
object to a view using
setAnimation(Animation)
or
startAnimation(Animation)
. The animation can alter the scale,
rotation, translation and alpha of a view over time. If the animation is
attached to a view that has children, the animation will affect the entire
subtree rooted by that node. When an animation is started, the framework will
take care of redrawing the appropriate views until the animation completes.
Sometimes it is essential that an application be able to verify that an action is being performed with the full knowledge and consent of the user, such as granting a permission request, making a purchase or clicking on an advertisement. Unfortunately, a malicious application could try to spoof the user into performing these actions, unaware, by concealing the intended purpose of the view. As a remedy, the framework offers a touch filtering mechanism that can be used to improve the security of views that provide access to sensitive functionality.
To enable touch filtering, call setFilterTouchesWhenObscured(boolean)
or set the
android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework
will discard touches that are received whenever the view's window is obscured by
another visible window. As a result, the view will not receive touches whenever a
toast, dialog or other window appears above the view's window.
For more fine-grained control over security, consider overriding the
onFilterTouchEventForSecurity(MotionEvent)
method to implement your own
security policy. See also MotionEvent.FLAG_WINDOW_IS_OBSCURED
.
ViewGroup
Modifier and Type | Class and Description |
---|---|
static class |
View.AccessibilityDelegate
This class represents a delegate that can be registered in a
View
to enhance accessibility support via composition rather via inheritance. |
static class |
View.BaseSavedState
Base class for derived classes that want to save and restore their own
state in
onSaveInstanceState() . |
static class |
View.DragShadowBuilder
Creates an image that the system displays during the drag and drop
operation.
|
static interface |
View.DrawingCacheQuality |
static interface |
View.FindViewFlags |
static interface |
View.FocusableMode |
static interface |
View.FocusDirection |
static interface |
View.FocusRealDirection |
static interface |
View.LayoutDir |
static class |
View.MeasureSpec
A MeasureSpec encapsulates the layout requirements passed from parent to child.
|
static interface |
View.OnApplyWindowInsetsListener
Listener for applying window insets on a view in a custom way.
|
static interface |
View.OnAttachStateChangeListener
Interface definition for a callback to be invoked when this view is attached
or detached from its window.
|
static interface |
View.OnClickListener
Interface definition for a callback to be invoked when a view is clicked.
|
static interface |
View.OnContextClickListener
Interface definition for a callback to be invoked when a view is context clicked.
|
static interface |
View.OnCreateContextMenuListener
Interface definition for a callback to be invoked when the context menu
for this view is being built.
|
static interface |
View.OnDragListener
Interface definition for a callback to be invoked when a drag is being dispatched
to this view.
|
static interface |
View.OnFocusChangeListener
Interface definition for a callback to be invoked when the focus state of
a view changed.
|
static interface |
View.OnGenericMotionListener
Interface definition for a callback to be invoked when a generic motion event is
dispatched to this view.
|
static interface |
View.OnHoverListener
Interface definition for a callback to be invoked when a hover event is
dispatched to this view.
|
static interface |
View.OnKeyListener
Interface definition for a callback to be invoked when a hardware key event is
dispatched to this view.
|
static interface |
View.OnLayoutChangeListener
Interface definition for a callback to be invoked when the layout bounds of a view
changes due to layout processing.
|
static interface |
View.OnLongClickListener
Interface definition for a callback to be invoked when a view has been clicked and held.
|
static interface |
View.OnScrollChangeListener
Interface definition for a callback to be invoked when the scroll
X or Y positions of a view change.
|
static interface |
View.OnSystemUiVisibilityChangeListener
Interface definition for a callback to be invoked when the status bar changes
visibility.
|
static interface |
View.OnTouchListener
Interface definition for a callback to be invoked when a touch event is
dispatched to this view.
|
static interface |
View.ResolvedLayoutDir |
static interface |
View.ScrollBarStyle |
static interface |
View.ScrollIndicators |
static interface |
View.TextAlignment |
static interface |
View.Visibility |
Modifier and Type | Field and Description |
---|---|
static int |
ACCESSIBILITY_CURSOR_POSITION_UNDEFINED
The undefined cursor position.
|
static int |
ACCESSIBILITY_LIVE_REGION_ASSERTIVE
Live region mode specifying that accessibility services should interrupt
ongoing speech to immediately announce changes to this view.
|
static int |
ACCESSIBILITY_LIVE_REGION_NONE
Live region mode specifying that accessibility services should not
automatically announce changes to this view.
|
static int |
ACCESSIBILITY_LIVE_REGION_POLITE
Live region mode specifying that accessibility services should announce
changes to this view.
|
static Property<View,Float> |
ALPHA
A Property wrapper around the
alpha functionality handled by the
setAlpha(float) and getAlpha() methods. |
static String |
DEBUG_LAYOUT_PROPERTY
When set to true, apps will draw debugging information about their layouts.
|
static int |
DRAG_FLAG_GLOBAL
Flag indicating that a drag can cross window boundaries.
|
static int |
DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION
When this flag is used with
DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE , the URI permission grant can be persisted across device
reboots until explicitly revoked with
Context.revokeUriPermission . |
static int |
DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION
When this flag is used with
DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE , the URI permission grant applies to any URI that is a prefix
match against the original granted URI. |
static int |
DRAG_FLAG_GLOBAL_URI_READ
When this flag is used with
DRAG_FLAG_GLOBAL , the drag recipient will be able to
request read access to the content URI(s) contained in the ClipData object. |
static int |
DRAG_FLAG_GLOBAL_URI_WRITE
When this flag is used with
DRAG_FLAG_GLOBAL , the drag recipient will be able to
request write access to the content URI(s) contained in the ClipData object. |
static int |
DRAG_FLAG_OPAQUE
Flag indicating that the drag shadow will be opaque.
|
static int |
DRAWING_CACHE_QUALITY_AUTO
Enables automatic quality mode for the drawing cache.
|
static int |
DRAWING_CACHE_QUALITY_HIGH
Enables high quality mode for the drawing cache.
|
static int |
DRAWING_CACHE_QUALITY_LOW
Enables low quality mode for the drawing cache.
|
protected static int[] |
EMPTY_STATE_SET
Indicates the view has no states set.
|
protected static int[] |
ENABLED_FOCUSED_SELECTED_STATE_SET
Indicates the view is enabled, focused and selected.
|
protected static int[] |
ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is enabled, focused, selected and its window
has the focus.
|
protected static int[] |
ENABLED_FOCUSED_STATE_SET
Indicates the view is enabled and has the focus.
|
protected static int[] |
ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
Indicates the view is enabled, focused and its window has the focus.
|
protected static int[] |
ENABLED_SELECTED_STATE_SET
Indicates the view is enabled and selected.
|
protected static int[] |
ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is enabled, selected and its window has the focus.
|
protected static int[] |
ENABLED_STATE_SET
Indicates the view is enabled.
|
protected static int[] |
ENABLED_WINDOW_FOCUSED_STATE_SET
Indicates the view is enabled and that its window has focus.
|
static int |
FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS
Find views that contain
AccessibilityNodeProvider . |
static int |
FIND_VIEWS_WITH_CONTENT_DESCRIPTION
Find find views that contain the specified content description.
|
static int |
FIND_VIEWS_WITH_TEXT
Find views that render the specified text.
|
static int |
FOCUS_BACKWARD
Use with
focusSearch(int) . |
static int |
FOCUS_DOWN
Use with
focusSearch(int) . |
static int |
FOCUS_FORWARD
Use with
focusSearch(int) . |
static int |
FOCUS_LEFT
Use with
focusSearch(int) . |
static int |
FOCUS_RIGHT
Use with
focusSearch(int) . |
static int |
FOCUS_UP
Use with
focusSearch(int) . |
static int |
FOCUSABLES_ALL
View flag indicating whether
addFocusables(ArrayList, int, int)
should add all focusable Views regardless if they are focusable in touch mode. |
static int |
FOCUSABLES_TOUCH_MODE
View flag indicating whether
addFocusables(ArrayList, int, int)
should add only Views focusable in touch mode. |
protected static int[] |
FOCUSED_SELECTED_STATE_SET
Indicates the view is focused and selected.
|
protected static int[] |
FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is focused, selected and its window has the focus.
|
protected static int[] |
FOCUSED_STATE_SET
Indicates the view is focused.
|
protected static int[] |
FOCUSED_WINDOW_FOCUSED_STATE_SET
Indicates the view has the focus and that its window has the focus.
|
static int |
GONE
This view is invisible, and it doesn't take any space for layout
purposes.
|
static int |
HAPTIC_FEEDBACK_ENABLED
View flag indicating whether this view should have haptic feedback
enabled for events such as long presses.
|
static int |
IMPORTANT_FOR_ACCESSIBILITY_AUTO
Automatically determine whether a view is important for accessibility.
|
static int |
IMPORTANT_FOR_ACCESSIBILITY_NO
The view is not important for accessibility.
|
static int |
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
The view is not important for accessibility, nor are any of its
descendant views.
|
static int |
IMPORTANT_FOR_ACCESSIBILITY_YES
The view is important for accessibility.
|
static int |
INVISIBLE
This view is invisible, but it still takes up space for layout purposes.
|
static int |
KEEP_SCREEN_ON
View flag indicating that the screen should remain on while the
window containing this view is visible to the user.
|
static int |
LAYER_TYPE_HARDWARE
Indicates that the view has a hardware layer.
|
static int |
LAYER_TYPE_NONE
Indicates that the view does not have a layer.
|
static int |
LAYER_TYPE_SOFTWARE
Indicates that the view has a software layer.
|
static int |
LAYOUT_DIRECTION_INHERIT
Horizontal layout direction of this view is inherited from its parent.
|
static int |
LAYOUT_DIRECTION_LOCALE
Horizontal layout direction of this view is from deduced from the default language
script for the locale.
|
static int |
LAYOUT_DIRECTION_LTR
Horizontal layout direction of this view is from Left to Right.
|
static int |
LAYOUT_DIRECTION_RTL
Horizontal layout direction of this view is from Right to Left.
|
static int |
LAYOUT_DIRECTION_UNDEFINED
A flag to indicate that the layout direction of this view has not been defined yet.
|
String[] |
mAttributes
Holds pairs of adjacent attribute data: attribute name followed by its value.
|
protected int |
mBottom
The distance in pixels from the top edge of this view's parent
to the bottom edge of this view.
|
boolean |
mCachingFailed
Set to true when drawing cache is enabled and cannot be created.
|
protected Context |
mContext
The application environment this view lives in.
|
protected Animation |
mCurrentAnimation
The animation currently associated with this view.
|
static boolean |
mDebugViewAttributes
When set to true, this view will save its attribute data.
|
static int |
MEASURED_HEIGHT_STATE_SHIFT
Bit shift of
MEASURED_STATE_MASK to get to the height bits
for functions that combine both width and height into a single int,
such as getMeasuredState() and the childState argument of
resolveSizeAndState(int, int, int) . |
static int |
MEASURED_SIZE_MASK
Bits of
getMeasuredWidthAndState() and
getMeasuredWidthAndState() that provide the actual measured size. |
static int |
MEASURED_STATE_MASK
Bits of
getMeasuredWidthAndState() and
getMeasuredWidthAndState() that provide the additional state bits. |
static int |
MEASURED_STATE_TOO_SMALL
Bit of
getMeasuredWidthAndState() and
getMeasuredWidthAndState() that indicates the measured size
is smaller that the space the view would like to have. |
protected InputEventConsistencyVerifier |
mInputEventConsistencyVerifier
Consistency verifier for debugging purposes.
|
protected ViewGroup.LayoutParams |
mLayoutParams
The layout parameters associated with this view and used by the parent
ViewGroup to determine how this view should be
laid out. |
protected int |
mLeft
The distance in pixels from the left edge of this view's parent
to the left edge of this view.
|
protected int |
mPaddingBottom
The bottom padding in pixels, that is the distance in pixels between the
bottom edge of this view and the bottom edge of its content.
|
protected int |
mPaddingLeft
The left padding in pixels, that is the distance in pixels between the
left edge of this view and the left edge of its content.
|
protected int |
mPaddingRight
The right padding in pixels, that is the distance in pixels between the
right edge of this view and the right edge of its content.
|
protected int |
mPaddingTop
The top padding in pixels, that is the distance in pixels between the
top edge of this view and the top edge of its content.
|
protected ViewParent |
mParent
The parent this view is attached to.
|
protected int |
mRight
The distance in pixels from the left edge of this view's parent
to the right edge of this view.
|
protected int |
mScrollX
The offset, in pixels, by which the content of this view is scrolled
horizontally.
|
protected int |
mScrollY
The offset, in pixels, by which the content of this view is scrolled
vertically.
|
protected Object |
mTag
The view's tag.
|
protected int |
mTop
The distance in pixels from the top edge of this view's parent
to the top edge of this view.
|
protected int |
mUserPaddingBottom
Cache the paddingBottom set by the user to append to the scrollbar's size.
|
protected int |
mUserPaddingLeft
Cache the paddingLeft set by the user to append to the scrollbar's size.
|
protected int |
mUserPaddingRight
Cache the paddingRight set by the user to append to the scrollbar's size.
|
static int |
NAVIGATION_BAR_TRANSIENT |
static int |
NAVIGATION_BAR_TRANSLUCENT |
static int |
NAVIGATION_BAR_TRANSPARENT |
static int |
NAVIGATION_BAR_UNHIDE |
static int |
NO_ID
Used to mark a View that has no ID.
|
static int |
OVER_SCROLL_ALWAYS
Always allow a user to over-scroll this view, provided it is a
view that can scroll.
|
static int |
OVER_SCROLL_IF_CONTENT_SCROLLS
Allow a user to over-scroll this view only if the content is large
enough to meaningfully scroll, provided it is a view that can scroll.
|
static int |
OVER_SCROLL_NEVER
Never allow a user to over-scroll this view.
|
protected static int[] |
PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET
Indicates the view is pressed, enabled, focused and selected.
|
protected static int[] |
PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, enabled, focused, selected and its window
has the focus.
|
protected static int[] |
PRESSED_ENABLED_FOCUSED_STATE_SET
Indicates the view is pressed, enabled and focused.
|
protected static int[] |
PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, enabled, focused and its window has the
focus.
|
protected static int[] |
PRESSED_ENABLED_SELECTED_STATE_SET
Indicates the view is pressed, enabled and selected.
|
protected static int[] |
PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, enabled, selected and its window has the
focus.
|
protected static int[] |
PRESSED_ENABLED_STATE_SET
Indicates the view is pressed and enabled.
|
protected static int[] |
PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, enabled and its window has the focus.
|
protected static int[] |
PRESSED_FOCUSED_SELECTED_STATE_SET
Indicates the view is pressed, focused and selected.
|
protected static int[] |
PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, focused, selected and its window has the focus.
|
protected static int[] |
PRESSED_FOCUSED_STATE_SET
Indicates the view is pressed and focused.
|
protected static int[] |
PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, focused and its window has the focus.
|
protected static int[] |
PRESSED_SELECTED_STATE_SET
Indicates the view is pressed and selected.
|
protected static int[] |
PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed, selected and its window has the focus.
|
protected static int[] |
PRESSED_STATE_SET
Indicates the view is pressed.
|
protected static int[] |
PRESSED_WINDOW_FOCUSED_STATE_SET
Indicates the view is pressed and its window has the focus.
|
static int |
PUBLIC_STATUS_BAR_VISIBILITY_MASK |
static Property<View,Float> |
ROTATION
A Property wrapper around the
rotation functionality handled by the
setRotation(float) and getRotation() methods. |
static Property<View,Float> |
ROTATION_X
A Property wrapper around the
rotationX functionality handled by the
setRotationX(float) and getRotationX() methods. |
static Property<View,Float> |
ROTATION_Y
A Property wrapper around the
rotationY functionality handled by the
setRotationY(float) and getRotationY() methods. |
static Property<View,Float> |
SCALE_X
A Property wrapper around the
scaleX functionality handled by the
setScaleX(float) and getScaleX() methods. |
static Property<View,Float> |
SCALE_Y
A Property wrapper around the
scaleY functionality handled by the
setScaleY(float) and getScaleY() methods. |
static int |
SCREEN_STATE_OFF
Indicates that the screen has changed state and is now off.
|
static int |
SCREEN_STATE_ON
Indicates that the screen has changed state and is now on.
|
static int |
SCROLL_AXIS_HORIZONTAL
Indicates scrolling along the horizontal axis.
|
static int |
SCROLL_AXIS_NONE
Indicates no axis of view scrolling.
|
static int |
SCROLL_AXIS_VERTICAL
Indicates scrolling along the vertical axis.
|
static int |
SCROLL_INDICATOR_BOTTOM
Scroll indicator direction for the bottom edge of the view.
|
static int |
SCROLL_INDICATOR_END
Scroll indicator direction for the ending edge of the view.
|
static int |
SCROLL_INDICATOR_LEFT
Scroll indicator direction for the left edge of the view.
|
static int |
SCROLL_INDICATOR_RIGHT
Scroll indicator direction for the right edge of the view.
|
static int |
SCROLL_INDICATOR_START
Scroll indicator direction for the starting edge of the view.
|
static int |
SCROLL_INDICATOR_TOP
Scroll indicator direction for the top edge of the view.
|
static int |
SCROLLBAR_POSITION_DEFAULT
Position the scroll bar at the default position as determined by the system.
|
static int |
SCROLLBAR_POSITION_LEFT
Position the scroll bar along the left edge.
|
static int |
SCROLLBAR_POSITION_RIGHT
Position the scroll bar along the right edge.
|
static int |
SCROLLBARS_INSIDE_INSET
The scrollbar style to display the scrollbars inside the padded area,
increasing the padding of the view.
|
static int |
SCROLLBARS_INSIDE_OVERLAY
The scrollbar style to display the scrollbars inside the content area,
without increasing the padding.
|
static int |
SCROLLBARS_OUTSIDE_INSET
The scrollbar style to display the scrollbars at the edge of the view,
increasing the padding of the view.
|
static int |
SCROLLBARS_OUTSIDE_OVERLAY
The scrollbar style to display the scrollbars at the edge of the view,
without increasing the padding.
|
protected static int[] |
SELECTED_STATE_SET
Indicates the view is selected.
|
protected static int[] |
SELECTED_WINDOW_FOCUSED_STATE_SET
Indicates the view is selected and that its window has the focus.
|
static int |
SOUND_EFFECTS_ENABLED
View flag indicating whether this view should have sound effects enabled
for events such as clicking and touching.
|
protected static boolean |
sPreserveMarginParamsInLayoutParamConversion
Prior to N, some ViewGroups would not convert LayoutParams properly even though both extend
MarginLayoutParams.
|
static int |
STATUS_BAR_DISABLE_BACK |
static int |
STATUS_BAR_DISABLE_CLOCK |
static int |
STATUS_BAR_DISABLE_EXPAND |
static int |
STATUS_BAR_DISABLE_HOME |
static int |
STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
static int |
STATUS_BAR_DISABLE_NOTIFICATION_ICONS |
static int |
STATUS_BAR_DISABLE_NOTIFICATION_TICKER |
static int |
STATUS_BAR_DISABLE_RECENT |
static int |
STATUS_BAR_DISABLE_SEARCH |
static int |
STATUS_BAR_DISABLE_SYSTEM_INFO |
static int |
STATUS_BAR_HIDDEN
Deprecated.
Use
SYSTEM_UI_FLAG_LOW_PROFILE instead. |
static int |
STATUS_BAR_TRANSIENT |
static int |
STATUS_BAR_TRANSLUCENT |
static int |
STATUS_BAR_TRANSPARENT |
static int |
STATUS_BAR_UNHIDE |
static int |
STATUS_BAR_VISIBLE
Deprecated.
Use
SYSTEM_UI_FLAG_VISIBLE instead. |
static int |
SYSTEM_UI_CLEARABLE_FLAGS
These are the system UI flags that can be cleared by events outside
of an application.
|
static int |
SYSTEM_UI_FLAG_FULLSCREEN
Flag for
setSystemUiVisibility(int) : View has requested to go
into the normal fullscreen mode so that its content can take over the screen
while still allowing the user to interact with the application. |
static int |
SYSTEM_UI_FLAG_HIDE_NAVIGATION
Flag for
setSystemUiVisibility(int) : View has requested that the
system navigation be temporarily hidden. |
static int |
SYSTEM_UI_FLAG_IMMERSIVE
Flag for
setSystemUiVisibility(int) : View would like to remain interactive when
hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION . |
static int |
SYSTEM_UI_FLAG_IMMERSIVE_STICKY
Flag for
setSystemUiVisibility(int) : View would like to remain interactive when
hiding the status bar with SYSTEM_UI_FLAG_FULLSCREEN and/or hiding the navigation
bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION . |
static int |
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Flag for
setSystemUiVisibility(int) : View would like its window
to be laid out as if it has requested
SYSTEM_UI_FLAG_FULLSCREEN , even if it currently hasn't. |
static int |
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Flag for
setSystemUiVisibility(int) : View would like its window
to be laid out as if it has requested
SYSTEM_UI_FLAG_HIDE_NAVIGATION , even if it currently hasn't. |
static int |
SYSTEM_UI_FLAG_LAYOUT_STABLE
Flag for
setSystemUiVisibility(int) : When using other layout
flags, we would like a stable view of the content insets given to
fitSystemWindows(Rect) . |
static int |
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
Flag for
setSystemUiVisibility(int) : Requests the status bar to draw in a mode that
is compatible with light status bar backgrounds. |
static int |
SYSTEM_UI_FLAG_LOW_PROFILE
Flag for
setSystemUiVisibility(int) : View has requested the
system UI to enter an unobtrusive "low profile" mode. |
static int |
SYSTEM_UI_FLAG_VISIBLE
Special constant for
setSystemUiVisibility(int) : View has
requested the system UI (status bar) to be visible (the default). |
static int |
SYSTEM_UI_LAYOUT_FLAGS
Flags that can impact the layout in relation to system UI.
|
static int |
SYSTEM_UI_TRANSPARENT |
static int |
TEXT_ALIGNMENT_CENTER
Center the paragraph, e.g.
|
static int |
TEXT_ALIGNMENT_GRAVITY
Default for the root view.
|
static int |
TEXT_ALIGNMENT_INHERIT
Default text alignment.
|
static int |
TEXT_ALIGNMENT_TEXT_END
Align to the end of the paragraph, e.g.
|
static int |
TEXT_ALIGNMENT_TEXT_START
Align to the start of the paragraph, e.g.
|
static int |
TEXT_ALIGNMENT_VIEW_END
Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved
layoutDirection is LTR, and ALIGN_LEFT otherwise.
|
static int |
TEXT_ALIGNMENT_VIEW_START
Align to the start of the view, which is ALIGN_LEFT if the view’s resolved
layoutDirection is LTR, and ALIGN_RIGHT otherwise.
|
static int |
TEXT_DIRECTION_ANY_RTL
Text direction is using "any-RTL" algorithm.
|
static int |
TEXT_DIRECTION_FIRST_STRONG
Text direction is using "first strong algorithm".
|
static int |
TEXT_DIRECTION_FIRST_STRONG_LTR
Text direction is using "first strong algorithm".
|
static int |
TEXT_DIRECTION_FIRST_STRONG_RTL
Text direction is using "first strong algorithm".
|
static int |
TEXT_DIRECTION_INHERIT
Text direction is inherited through
ViewGroup |
static int |
TEXT_DIRECTION_LOCALE
Text direction is coming from the system Locale.
|
static int |
TEXT_DIRECTION_LTR
Text direction is forced to LTR.
|
static int |
TEXT_DIRECTION_RTL
Text direction is forced to RTL.
|
static Property<View,Float> |
TRANSLATION_X
A Property wrapper around the
translationX functionality handled by the
setTranslationX(float) and getTranslationX() methods. |
static Property<View,Float> |
TRANSLATION_Y
A Property wrapper around the
translationY functionality handled by the
setTranslationY(float) and getTranslationY() methods. |
static Property<View,Float> |
TRANSLATION_Z
A Property wrapper around the
translationZ functionality handled by the
setTranslationZ(float) and getTranslationZ() methods. |
protected static String |
VIEW_LOG_TAG
The logging tag used by this class with android.util.Log.
|
static int |
VISIBLE
This view is visible.
|
protected static int[] |
WINDOW_FOCUSED_STATE_SET
Indicates the view's window has focus.
|
static Property<View,Float> |
X
|
static Property<View,Float> |
Y
|
static Property<View,Float> |
Z
|
Constructor and Description |
---|
View(Context context)
Simple constructor to use when creating a view from code.
|
View(Context context,
AttributeSet attrs)
Constructor that is called when inflating a view from XML.
|
View(Context context,
AttributeSet attrs,
int defStyleAttr)
Perform inflation from XML and apply a class-specific base style from a
theme attribute.
|
View(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Perform inflation from XML and apply a class-specific base style from a
theme attribute or style resource.
|
Modifier and Type | Method and Description |
---|---|
void |
addChildrenForAccessibility(ArrayList<View> outChildren)
Adds the children of this View relevant for accessibility to the given list
as output.
|
void |
addFocusables(ArrayList<View> views,
int direction)
Add any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
|
void |
addFocusables(ArrayList<View> views,
int direction,
int focusableMode)
Adds any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
|
void |
addFrameMetricsListener(Window window,
Window.OnFrameMetricsAvailableListener listener,
Handler handler)
Set an observer to collect stats for each frame rendered for this view.
|
void |
addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)
Add a listener for attach state changes.
|
void |
addOnLayoutChangeListener(View.OnLayoutChangeListener listener)
Add a listener that will be called when the bounds of the view change due to
layout processing.
|
void |
addTouchables(ArrayList<View> views)
Add any touchable views that are descendants of this view (possibly
including this view if it is touchable itself) to views.
|
ViewPropertyAnimator |
animate()
This method returns a ViewPropertyAnimator object, which can be used to animate
specific properties on this View.
|
void |
announceForAccessibility(CharSequence text)
Convenience method for sending a
AccessibilityEvent.TYPE_ANNOUNCEMENT
AccessibilityEvent to make an announcement which is related to some
sort of a context change for which none of the events representing UI transitions
is a good fit. |
void |
applyDrawableToTransparentRegion(Drawable dr,
Region region)
Given a Drawable whose bounds have been set to draw into this view,
update a Region being computed for
gatherTransparentRegion(android.graphics.Region) so
that any non-transparent parts of the Drawable are removed from the
given transparent region. |
protected boolean |
awakenScrollBars()
Trigger the scrollbars to draw.
|
protected boolean |
awakenScrollBars(int startDelay)
Trigger the scrollbars to draw.
|
protected boolean |
awakenScrollBars(int startDelay,
boolean invalidate)
Trigger the scrollbars to draw.
|
void |
bringToFront()
Change the view's z order in the tree, so it's on top of other sibling
views.
|
void |
buildDrawingCache()
Calling this method is equivalent to calling
buildDrawingCache(false) . |
void |
buildDrawingCache(boolean autoScale)
Forces the drawing cache to be built if the drawing cache is invalid.
|
void |
buildLayer()
Forces this view's layer to be created and this view to be rendered
into its layer.
|
boolean |
callOnClick()
Directly call any attached OnClickListener.
|
void |
cancelDragAndDrop()
Cancels an ongoing drag and drop operation.
|
void |
cancelLongPress()
Cancels a pending long press.
|
void |
cancelPendingInputEvents()
Cancel any deferred high-level input events that were previously posted to the event queue.
|
boolean |
canHaveDisplayList()
A view that is not attached or hardware accelerated cannot create a display list.
|
boolean |
canResolveLayoutDirection()
Check if layout direction resolution can be done.
|
boolean |
canResolveTextAlignment()
Check if text alignment resolution can be done.
|
boolean |
canResolveTextDirection()
Check if text direction resolution can be done.
|
boolean |
canScrollHorizontally(int direction)
Check if this view can be scrolled horizontally in a certain direction.
|
boolean |
canScrollVertically(int direction)
Check if this view can be scrolled vertically in a certain direction.
|
void |
captureTransitioningViews(List<View> transitioningViews)
Gets the Views in the hierarchy affected by entering and exiting Activity Scene transitions.
|
boolean |
checkInputConnectionProxy(View view)
Called by the
InputMethodManager
when a view who is not the current
input connection target is trying to make a call on the manager. |
void |
clearAccessibilityFocus()
Call this to try to clear accessibility focus of this view.
|
void |
clearAnimation()
Cancels any animations for this view.
|
void |
clearFocus()
Called when this view wants to give up focus.
|
static int |
combineMeasuredStates(int curState,
int newState)
Merge two states as returned by
getMeasuredState() . |
protected boolean |
computeFitSystemWindows(Rect inoutInsets,
Rect outLocalInsets) |
protected int |
computeHorizontalScrollExtent()
Compute the horizontal extent of the horizontal scrollbar's thumb
within the horizontal range.
|
protected int |
computeHorizontalScrollOffset()
Compute the horizontal offset of the horizontal scrollbar's thumb
within the horizontal range.
|
protected int |
computeHorizontalScrollRange()
Compute the horizontal range that the horizontal scrollbar
represents.
|
protected void |
computeOpaqueFlags() |
void |
computeScroll()
Called by a parent to request that a child update its values for mScrollX
and mScrollY if necessary.
|
WindowInsets |
computeSystemWindowInsets(WindowInsets in,
Rect outLocalInsets)
Compute insets that should be consumed by this view and the ones that should propagate
to those under it.
|
protected int |
computeVerticalScrollExtent()
Compute the vertical extent of the vertical scrollbar's thumb
within the vertical range.
|
protected int |
computeVerticalScrollOffset()
Compute the vertical offset of the vertical scrollbar's thumb
within the horizontal range.
|
protected int |
computeVerticalScrollRange()
Compute the vertical range that the vertical scrollbar represents.
|
AccessibilityNodeInfo |
createAccessibilityNodeInfo()
Returns an
AccessibilityNodeInfo representing this view from the
point of view of an AccessibilityService . |
AccessibilityNodeInfo |
createAccessibilityNodeInfoInternal() |
void |
createContextMenu(ContextMenu menu)
Show the context menu for this view.
|
Bitmap |
createSnapshot(Bitmap.Config quality,
int backgroundColor,
boolean skipChildren)
Create a snapshot of the view into a bitmap.
|
protected void |
damageInParent()
Tells the parent view to damage this view's bounds.
|
void |
debug()
Prints information about this view in the log output, with the tag
VIEW_LOG_TAG . |
protected void |
debug(int depth)
Prints information about this view in the log output, with the tag
VIEW_LOG_TAG . |
protected static String |
debugIndent(int depth)
Creates a string of whitespaces used for indentation.
|
void |
destroyDrawingCache()
Frees the resources used by the drawing cache.
|
protected void |
destroyHardwareResources()
Destroys all hardware rendering resources.
|
boolean |
dispatchActivityResult(String who,
int requestCode,
int resultCode,
Intent data)
If this View corresponds to the calling who, dispatches the activity result.
|
WindowInsets |
dispatchApplyWindowInsets(WindowInsets insets)
Request to apply the given window insets to this view or another view in its subtree.
|
void |
dispatchConfigurationChanged(Configuration newConfig)
Dispatch a notification about a resource configuration change down
the view hierarchy.
|
void |
dispatchDisplayHint(int hint)
Dispatch a hint about whether this view is displayed.
|
boolean |
dispatchDragEvent(DragEvent event)
Detects if this View is enabled and has a drag event listener.
|
protected void |
dispatchDraw(Canvas canvas)
Called by draw to draw the child views.
|
void |
dispatchDrawableHotspotChanged(float x,
float y)
Dispatches drawableHotspotChanged to all of this View's children.
|
void |
dispatchFinishTemporaryDetach()
Dispatch
onFinishTemporaryDetach() to this View and its direct children if this is
a container View. |
protected boolean |
dispatchGenericFocusedEvent(MotionEvent event)
Dispatch a generic motion event to the currently focused view.
|
boolean |
dispatchGenericMotionEvent(MotionEvent event)
Dispatch a generic motion event.
|
protected boolean |
dispatchGenericPointerEvent(MotionEvent event)
Dispatch a generic motion event to the view under the first pointer.
|
protected void |
dispatchGetDisplayList()
This method is used by ViewGroup to cause its children to restore or recreate their
display lists.
|
protected boolean |
dispatchHoverEvent(MotionEvent event)
Dispatch a hover event.
|
boolean |
dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
|
boolean |
dispatchKeyEventPreIme(KeyEvent event)
Dispatch a key event before it is processed by any input method
associated with the view hierarchy.
|
boolean |
dispatchKeyShortcutEvent(KeyEvent event)
Dispatches a key shortcut event.
|
boolean |
dispatchNestedFling(float velocityX,
float velocityY,
boolean consumed)
Dispatch a fling to a nested scrolling parent.
|
boolean |
dispatchNestedPreFling(float velocityX,
float velocityY)
Dispatch a fling to a nested scrolling parent before it is processed by this view.
|
boolean |
dispatchNestedPrePerformAccessibilityAction(int action,
Bundle arguments)
Report an accessibility action to this view's parents for delegated processing.
|
boolean |
dispatchNestedPreScroll(int dx,
int dy,
int[] consumed,
int[] offsetInWindow)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it.
|
boolean |
dispatchNestedScroll(int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
int[] offsetInWindow)
Dispatch one step of a nested scroll in progress.
|
boolean |
dispatchPointerEvent(MotionEvent event)
Dispatch a pointer event.
|
boolean |
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
Dispatches an
AccessibilityEvent to the View first and then
to its children for adding their text content to the event. |
boolean |
dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) |
void |
dispatchProvideStructure(ViewStructure structure)
Dispatch creation of
ViewStructure down the hierarchy. |
protected void |
dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Called by
restoreHierarchyState(android.util.SparseArray) to retrieve the
state for this view and its children. |
protected void |
dispatchSaveInstanceState(SparseArray<Parcelable> container)
Called by
saveHierarchyState(android.util.SparseArray) to store the state for
this view and its children. |
protected void |
dispatchSetActivated(boolean activated)
Dispatch setActivated to all of this View's children.
|
protected void |
dispatchSetPressed(boolean pressed)
Dispatch setPressed to all of this View's children.
|
protected void |
dispatchSetSelected(boolean selected)
Dispatch setSelected to all of this View's children.
|
void |
dispatchStartTemporaryDetach()
Dispatch
onStartTemporaryDetach() to this View and its direct children if this is
a container View. |
void |
dispatchSystemUiVisibilityChanged(int visibility)
Dispatch callbacks to
setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) down
the view hierarchy. |
boolean |
dispatchTouchEvent(MotionEvent event)
Pass the touch screen motion event down to the target view, or this
view if it is the target.
|
boolean |
dispatchTrackballEvent(MotionEvent event)
Pass a trackball motion event down to the focused view.
|
boolean |
dispatchUnhandledMove(View focused,
int direction)
This method is the last chance for the focused view and its ancestors to
respond to an arrow key.
|
protected void |
dispatchVisibilityChanged(View changedView,
int visibility)
Dispatch a view visibility change down the view hierarchy.
|
void |
dispatchWindowFocusChanged(boolean hasFocus)
Called when the window containing this view gains or loses window focus.
|
void |
dispatchWindowSystemUiVisiblityChanged(int visible)
Dispatch callbacks to
onWindowSystemUiVisibilityChanged(int) down
the view hierarchy. |
void |
dispatchWindowVisibilityChanged(int visibility)
Dispatch a window visibility change down the view hierarchy.
|
void |
draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
|
void |
drawableHotspotChanged(float x,
float y)
This function is called whenever the view hotspot changes and needs to
be propagated to drawables or child views managed by the view.
|
protected void |
drawableStateChanged()
This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown.
|
void |
encode(ViewHierarchyEncoder stream) |
protected void |
encodeProperties(ViewHierarchyEncoder stream) |
View |
findFocus()
Find the view in the hierarchy rooted at this view that currently has
focus.
|
void |
findNamedViews(Map<String,View> namedElements)
Adds all Views that have
getTransitionName() non-null to namedElements. |
View |
findViewByAccessibilityIdTraversal(int accessibilityId)
Performs the traversal to find a view by its unuque and stable accessibility id.
|
View |
findViewById(int id)
Look for a child view with the given id.
|
View |
findViewByPredicate(Predicate<View> predicate)
Look for a child view that matches the specified predicate.
|
View |
findViewByPredicateInsideOut(View start,
Predicate<View> predicate)
Look for a child view that matches the specified predicate,
starting with the specified view and its descendents and then
recusively searching the ancestors and siblings of that view
until this view is reached.
|
protected View |
findViewByPredicateTraversal(Predicate<View> predicate,
View childToSkip) |
void |
findViewsWithText(ArrayList<View> outViews,
CharSequence searched,
int flags)
Finds the Views that contain given text.
|
protected View |
findViewTraversal(int id) |
View |
findViewWithTag(Object tag)
Look for a child view with the given tag.
|
protected View |
findViewWithTagTraversal(Object tag) |
boolean |
fitsSystemWindows() |
protected boolean |
fitSystemWindows(Rect insets)
Deprecated.
As of API 20 use
dispatchApplyWindowInsets(WindowInsets) to apply
insets to views. Views should override onApplyWindowInsets(WindowInsets) or use
setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener)
to implement handling their own insets. |
View |
focusSearch(int direction)
Find the nearest view in the specified direction that can take focus.
|
void |
forceHasOverlappingRendering(boolean hasOverlappingRendering)
Sets the behavior for overlapping rendering for this view (see
hasOverlappingRendering() for more details on this behavior). |
void |
forceLayout()
Forces this view to be laid out during the next layout pass.
|
boolean |
gatherTransparentRegion(Region region)
This is used by the RootView to perform an optimization when
the view hierarchy contains one or several SurfaceView.
|
static int |
generateViewId()
Generate a value suitable for use in
setId(int) . |
CharSequence |
getAccessibilityClassName()
Return the class name of this object to be used for accessibility purposes.
|
View.AccessibilityDelegate |
getAccessibilityDelegate()
Returns the delegate for implementing accessibility support via
composition.
|
int |
getAccessibilityLiveRegion()
Gets the live region mode for this View.
|
AccessibilityNodeProvider |
getAccessibilityNodeProvider()
Gets the provider for managing a virtual view hierarchy rooted at this View
and reported to
AccessibilityService s
that explore the window content. |
int |
getAccessibilitySelectionEnd() |
int |
getAccessibilitySelectionStart() |
int |
getAccessibilityTraversalAfter()
Gets the id of a view after which this one is visited in accessibility traversal.
|
int |
getAccessibilityTraversalBefore()
Gets the id of a view before which this one is visited in accessibility traversal.
|
int |
getAccessibilityViewId()
Gets the unique identifier of this view on the screen for accessibility purposes.
|
int |
getAccessibilityWindowId()
Gets the unique identifier of the window in which this View reseides.
|
float |
getAlpha()
The opacity of the view.
|
Animation |
getAnimation()
Get the animation currently associated with this view.
|
IBinder |
getApplicationWindowToken()
Retrieve a unique token identifying the top-level "real" window of
the window that this view is attached to.
|
Drawable |
getBackground()
Gets the background drawable
|
ColorStateList |
getBackgroundTintList()
Return the tint applied to the background drawable, if specified.
|
PorterDuff.Mode |
getBackgroundTintMode()
Return the blending mode used to apply the tint to the background
drawable, if specified.
|
int |
getBaseline()
Return the offset of the widget's text baseline from the widget's top
boundary.
|
int |
getBottom()
Bottom position of this view relative to its parent.
|
protected float |
getBottomFadingEdgeStrength()
Returns the strength, or intensity, of the bottom faded edge.
|
protected int |
getBottomPaddingOffset()
Amount by which to extend the bottom fading region.
|
void |
getBoundsOnScreen(Rect outRect)
Gets the location of this view in screen coordinates.
|
void |
getBoundsOnScreen(Rect outRect,
boolean clipToParent)
Gets the location of this view in screen coordinates.
|
float |
getCameraDistance()
Gets the distance along the Z axis from the camera to this view.
|
Rect |
getClipBounds()
Returns a copy of the current
clipBounds . |
boolean |
getClipBounds(Rect outRect)
Populates an output rectangle with the clip bounds of the view,
returning
true if successful or false if the view's
clip bounds are null . |
boolean |
getClipToOutline()
Returns whether the Outline should be used to clip the contents of the View.
|
CharSequence |
getContentDescription()
Returns the
View 's content description. |
Context |
getContext()
Returns the context the view is running in, through which it can
access the current theme, resources, etc.
|
protected ContextMenu.ContextMenuInfo |
getContextMenuInfo()
Views should implement this if they have extra information to associate
with the context menu.
|
static int |
getDefaultSize(int size,
int measureSpec)
Utility to return a default size.
|
Display |
getDisplay()
Gets the logical display to which the view's window has been attached.
|
int[] |
getDrawableState()
Return an array of resource IDs of the drawable states representing the
current state of the view.
|
Bitmap |
getDrawingCache()
Calling this method is equivalent to calling
getDrawingCache(false) . |
Bitmap |
getDrawingCache(boolean autoScale)
Returns the bitmap in which this view drawing is cached.
|
int |
getDrawingCacheBackgroundColor() |
int |
getDrawingCacheQuality()
Returns the quality of the drawing cache.
|
void |
getDrawingRect(Rect outRect)
Return the visible drawing bounds of your view.
|
long |
getDrawingTime()
Return the time at which the drawing of the view hierarchy started.
|
float |
getElevation()
The base elevation of this view relative to its parent, in pixels.
|
protected int |
getFadeHeight(boolean offsetRequired) |
protected int |
getFadeTop(boolean offsetRequired) |
boolean |
getFilterTouchesWhenObscured()
Gets whether the framework should discard touches when the view's
window is obscured by another visible window.
|
boolean |
getFitsSystemWindows()
Check for state of
setFitsSystemWindows(boolean) . |
ArrayList<View> |
getFocusables(int direction)
Find and return all focusable views that are descendants of this view,
possibly including this view if it is focusable itself.
|
void |
getFocusedRect(Rect r)
When a view has focus and the user navigates away from it, the next view is searched for
starting from the rectangle filled in by this method.
|
Drawable |
getForeground()
Returns the drawable used as the foreground of this View.
|
int |
getForegroundGravity()
Describes how the foreground is positioned.
|
ColorStateList |
getForegroundTintList()
Return the tint applied to the foreground drawable, if specified.
|
PorterDuff.Mode |
getForegroundTintMode()
Return the blending mode used to apply the tint to the foreground
drawable, if specified.
|
boolean |
getGlobalVisibleRect(Rect r) |
boolean |
getGlobalVisibleRect(Rect r,
Point globalOffset)
If some part of this view is not clipped by any of its parents, then
return that area in r in global (root) coordinates.
|
Handler |
getHandler() |
ThreadedRenderer |
getHardwareRenderer() |
boolean |
getHasOverlappingRendering()
Returns the value for overlapping rendering that is used internally.
|
int |
getHeight()
Return the height of your view.
|
void |
getHitRect(Rect outRect)
Hit rectangle in parent's coordinates
|
int |
getHorizontalFadingEdgeLength()
Returns the size of the horizontal faded edges used to indicate that more
content in this view is visible.
|
protected int |
getHorizontalScrollbarHeight()
Returns the height of the horizontal scrollbar.
|
protected float |
getHorizontalScrollFactor()
Gets a scale factor that determines the distance the view should scroll
horizontally in response to
MotionEvent.ACTION_SCROLL . |
void |
getHotspotBounds(Rect outRect)
Populates
outRect with the hotspot bounds. |
int |
getId()
Returns this view's identifier.
|
int |
getImportantForAccessibility()
Gets the mode for determining whether this View is important for accessibility
which is if it fires accessibility events and if it is reported to
accessibility services that query the screen.
|
Matrix |
getInverseMatrix()
Utility method to retrieve the inverse of the current mMatrix property.
|
CharSequence |
getIterableTextForAccessibility()
Gets the text reported for accessibility purposes.
|
AccessibilityIterators.TextSegmentIterator |
getIteratorForGranularity(int granularity) |
boolean |
getKeepScreenOn()
Returns whether the screen should remain on, corresponding to the current
value of
KEEP_SCREEN_ON . |
KeyEvent.DispatcherState |
getKeyDispatcherState()
Return the global
KeyEvent.DispatcherState
for this view's window. |
int |
getLabelFor()
Gets the id of a view for which this view serves as a label for
accessibility purposes.
|
int |
getLayerType()
Indicates what type of layer is currently associated with this view.
|
int |
getLayoutDirection()
Returns the resolved layout direction for this view.
|
ViewGroup.LayoutParams |
getLayoutParams()
Get the LayoutParams associated with this view.
|
int |
getLeft()
Left position of this view relative to its parent.
|
protected float |
getLeftFadingEdgeStrength()
Returns the strength, or intensity, of the left faded edge.
|
protected int |
getLeftPaddingOffset()
Amount by which to extend the left fading region.
|
boolean |
getLocalVisibleRect(Rect r) |
void |
getLocationInSurface(int[] location)
Compute the view's coordinate within the surface.
|
void |
getLocationInWindow(int[] outLocation)
Computes the coordinates of this view in its window.
|
int[] |
getLocationOnScreen() |
void |
getLocationOnScreen(int[] outLocation)
Computes the coordinates of this view on the screen.
|
Matrix |
getMatrix()
The transform matrix of this view, which is calculated based on the current
rotation, scale, and pivot properties.
|
int |
getMeasuredHeight()
Like
getMeasuredHeightAndState() , but only returns the
raw width component (that is the result is masked by
MEASURED_SIZE_MASK ). |
int |
getMeasuredHeightAndState()
Return the full height measurement information for this view as computed
by the most recent call to
measure(int, int) . |
int |
getMeasuredState()
Return only the state bits of
getMeasuredWidthAndState()
and getMeasuredHeightAndState() , combined into one integer. |
int |
getMeasuredWidth()
Like
getMeasuredWidthAndState() , but only returns the
raw width component (that is the result is masked by
MEASURED_SIZE_MASK ). |
int |
getMeasuredWidthAndState()
Return the full width measurement information for this view as computed
by the most recent call to
measure(int, int) . |
int |
getMinimumHeight()
Returns the minimum height of the view.
|
int |
getMinimumWidth()
Returns the minimum width of the view.
|
int |
getNextFocusDownId()
Gets the id of the view to use when the next focus is
FOCUS_DOWN . |
int |
getNextFocusForwardId()
Gets the id of the view to use when the next focus is
FOCUS_FORWARD . |
int |
getNextFocusLeftId()
Gets the id of the view to use when the next focus is
FOCUS_LEFT . |
int |
getNextFocusRightId()
Gets the id of the view to use when the next focus is
FOCUS_RIGHT . |
int |
getNextFocusUpId()
Gets the id of the view to use when the next focus is
FOCUS_UP . |
View.OnFocusChangeListener |
getOnFocusChangeListener()
Returns the focus-change callback registered for this view.
|
Insets |
getOpticalInsets() |
ViewOutlineProvider |
getOutlineProvider()
Returns the current
ViewOutlineProvider of the view, which generates the Outline
that defines the shape of the shadow it casts, and enables outline clipping. |
void |
getOutsets(Rect outOutsetRect)
Returns the outsets, which areas of the device that aren't a surface, but we would like to
treat them as such.
|
ViewOverlay |
getOverlay()
Returns the overlay for this view, creating it if it does not yet exist.
|
int |
getOverScrollMode()
Returns the over-scroll mode for this view.
|
int |
getPaddingBottom()
Returns the bottom padding of this view.
|
int |
getPaddingEnd()
Returns the end padding of this view depending on its resolved layout direction.
|
int |
getPaddingLeft()
Returns the left padding of this view.
|
int |
getPaddingRight()
Returns the right padding of this view.
|
int |
getPaddingStart()
Returns the start padding of this view depending on its resolved layout direction.
|
int |
getPaddingTop()
Returns the top padding of this view.
|
ViewParent |
getParent()
Gets the parent of this view.
|
ViewParent |
getParentForAccessibility()
Gets the parent for accessibility purposes.
|
float |
getPivotX()
|
float |
getPivotY()
|
PointerIcon |
getPointerIcon()
Gets the pointer icon for the current view.
|
int |
getRawLayoutDirection()
Returns the layout direction for this view.
|
int |
getRawTextAlignment()
Return the value specifying the text alignment or policy that was set with
setTextAlignment(int) . |
int |
getRawTextDirection()
Return the value specifying the text direction or policy that was set with
setTextDirection(int) . |
Resources |
getResources()
Returns the resources associated with this view.
|
boolean |
getRevealOnFocusHint()
Returns this view's preference for reveal behavior when it gains focus.
|
int |
getRight()
Right position of this view relative to its parent.
|
protected float |
getRightFadingEdgeStrength()
Returns the strength, or intensity, of the right faded edge.
|
protected int |
getRightPaddingOffset()
Amount by which to extend the right fading region.
|
View |
getRootView()
Finds the topmost view in the current view hierarchy.
|
WindowInsets |
getRootWindowInsets()
Provide original WindowInsets that are dispatched to the view hierarchy.
|
float |
getRotation()
The degrees that the view is rotated around the pivot point.
|
float |
getRotationX()
The degrees that the view is rotated around the horizontal axis through the pivot point.
|
float |
getRotationY()
The degrees that the view is rotated around the vertical axis through the pivot point.
|
float |
getScaleX()
The amount that the view is scaled in x around the pivot point, as a proportion of
the view's unscaled width.
|
float |
getScaleY()
The amount that the view is scaled in y around the pivot point, as a proportion of
the view's unscaled height.
|
int |
getScrollBarDefaultDelayBeforeFade()
Returns the delay before scrollbars fade.
|
int |
getScrollBarFadeDuration()
Returns the scrollbar fade duration.
|
int |
getScrollBarSize()
Returns the scrollbar size.
|
int |
getScrollBarStyle()
Returns the current scrollbar style.
|
int |
getScrollIndicators()
Returns a bitmask representing the enabled scroll indicators.
|
int |
getScrollX()
Return the scrolled left position of this view.
|
int |
getScrollY()
Return the scrolled top position of this view.
|
int |
getSolidColor()
Override this if your view is known to always be drawn on top of a solid color background,
and needs to draw fading edges.
|
StateListAnimator |
getStateListAnimator()
Returns the current StateListAnimator if exists.
|
protected int |
getSuggestedMinimumHeight()
Returns the suggested minimum height that the view should use.
|
protected int |
getSuggestedMinimumWidth()
Returns the suggested minimum width that the view should use.
|
int |
getSystemUiVisibility()
Returns the last
setSystemUiVisibility(int) that this view has requested. |
Object |
getTag()
Returns this view's tag.
|
Object |
getTag(int key)
Returns the tag associated with this view and the specified key.
|
int |
getTextAlignment()
Return the resolved text alignment.
|
int |
getTextDirection()
Return the resolved text direction.
|
int |
getTop()
Top position of this view relative to its parent.
|
protected float |
getTopFadingEdgeStrength()
Returns the strength, or intensity, of the top faded edge.
|
protected int |
getTopPaddingOffset()
Amount by which to extend the top fading region.
|
ArrayList<View> |
getTouchables()
Find and return all touchable views that are descendants of this view,
possibly including this view if it is touchable itself.
|
TouchDelegate |
getTouchDelegate()
Gets the TouchDelegate for this View.
|
float |
getTransitionAlpha()
This property is hidden and intended only for use by the Fade transition, which
animates it to produce a visual translucency that does not side-effect (or get
affected by) the real alpha property.
|
String |
getTransitionName()
Returns the name of the View to be used to identify Views in Transitions.
|
float |
getTranslationX()
The horizontal location of this view relative to its
left position. |
float |
getTranslationY()
The vertical location of this view relative to its
top position. |
float |
getTranslationZ()
The depth location of this view relative to its
elevation . |
int |
getVerticalFadingEdgeLength()
Returns the size of the vertical faded edges used to indicate that more
content in this view is visible.
|
int |
getVerticalScrollbarPosition() |
int |
getVerticalScrollbarWidth()
Returns the width of the vertical scrollbar.
|
protected float |
getVerticalScrollFactor()
Gets a scale factor that determines the distance the view should scroll
vertically in response to
MotionEvent.ACTION_SCROLL . |
ViewRootImpl |
getViewRootImpl()
Gets the view root associated with the View.
|
ViewTreeObserver |
getViewTreeObserver()
Returns the ViewTreeObserver for this view's hierarchy.
|
int |
getVisibility()
Returns the visibility status for this view.
|
int |
getWidth()
Return the width of the your view.
|
protected int |
getWindowAttachCount() |
void |
getWindowDisplayFrame(Rect outRect)
Like
getWindowVisibleDisplayFrame(android.graphics.Rect) , but returns the "full" display frame this window
is currently in without any insets. |
WindowId |
getWindowId()
Retrieve the
WindowId for the window this view is
currently attached to. |
int |
getWindowSystemUiVisibility()
Returns the current system UI visibility that is currently set for
the entire window.
|
IBinder |
getWindowToken()
Retrieve a unique token identifying the window this view is attached to.
|
int |
getWindowVisibility()
|
void |
getWindowVisibleDisplayFrame(Rect outRect)
Retrieve the overall visible display size in which the window this view is
attached to has been positioned in.
|
float |
getX()
The visual x position of this view, in pixels.
|
float |
getY()
The visual y position of this view, in pixels.
|
float |
getZ()
The visual z position of this view, in pixels.
|
protected boolean |
handleScrollBarDragging(MotionEvent event)
Handles scroll bar dragging by mouse input.
|
boolean |
hasFocus()
Returns true if this view has focus itself, or is the ancestor of the
view that has focus.
|
boolean |
hasFocusable()
Returns true if this view is focusable or if it contains a reachable View
for which
hasFocusable() returns true. |
protected boolean |
hasHoveredChild()
Returns true if the view has a child to which it has recently sent
MotionEvent.ACTION_HOVER_ENTER . |
boolean |
hasNestedScrollingParent()
Returns true if this view has a nested scrolling parent.
|
boolean |
hasOnClickListeners()
Return whether this view has an attached OnClickListener.
|
protected boolean |
hasOpaqueScrollbars() |
boolean |
hasOverlappingRendering()
Returns whether this View has content which overlaps.
|
boolean |
hasShadow()
HierarchyViewer only
|
boolean |
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.
|
boolean |
hasWindowFocus()
Returns true if this view is in a window that currently has window focus.
|
boolean |
includeForAccessibility()
Whether to regard this view for accessibility.
|
static View |
inflate(Context context,
int resource,
ViewGroup root)
Inflate a view from an XML resource.
|
protected void |
initializeFadingEdge(TypedArray a)
Initializes the fading edges from a given set of styled attributes.
|
protected void |
initializeFadingEdgeInternal(TypedArray a)
Initializes the fading edges from a given set of styled attributes.
|
protected void |
initializeScrollbars(TypedArray a)
Initializes the scrollbars from a given set of styled attributes.
|
protected void |
initializeScrollbarsInternal(TypedArray a)
Initializes the scrollbars from a given set of styled attributes.
|
protected void |
internalSetPadding(int left,
int top,
int right,
int bottom) |
void |
invalidate()
Invalidate the whole view.
|
void |
invalidate(int l,
int t,
int r,
int b)
Mark the area defined by the rect (l,t,r,b) as needing to be drawn.
|
void |
invalidate(Rect dirty)
Mark the area defined by dirty as needing to be drawn.
|
void |
invalidateDrawable(Drawable drawable)
Invalidates the specified Drawable.
|
void |
invalidateOutline()
Called to rebuild this View's Outline from its
outline provider |
protected void |
invalidateParentCaches()
Used to indicate that the parent of this view should clear its caches.
|
protected void |
invalidateParentIfNeeded()
Used to indicate that the parent of this view should be invalidated.
|
protected void |
invalidateParentIfNeededAndWasQuickRejected() |
boolean |
isAccessibilityFocused()
Returns whether this View is accessibility focused.
|
boolean |
isAccessibilitySelectionExtendable()
Gets whether accessibility selection can be extended.
|
boolean |
isActionableForAccessibility()
Returns whether the View is considered actionable from
accessibility perspective.
|
boolean |
isActivated()
Indicates the activation state of this view.
|
boolean |
isAssistBlocked() |
boolean |
isAttachedToWindow()
Returns true if this view is currently attached to a window.
|
boolean |
isClickable()
Indicates whether this view reacts to click events or not.
|
boolean |
isContextClickable()
Indicates whether this view reacts to context clicks or not.
|
boolean |
isDirty()
True if this view has changed since the last time being drawn.
|
boolean |
isDrawingCacheEnabled()
Indicates whether the drawing cache is enabled for this view.
|
boolean |
isDuplicateParentStateEnabled()
Indicates whether this duplicates its drawable state from its parent.
|
boolean |
isEnabled()
Returns the enabled status for this view.
|
boolean |
isFocusable()
Returns whether this View is able to take focus.
|
boolean |
isFocusableInTouchMode()
When a view is focusable, it may not want to take focus when in touch mode.
|
boolean |
isFocused()
Returns true if this view has focus
|
boolean |
isForegroundInsidePadding()
Magic bit used to support features of framework-internal window decor implementation details.
|
boolean |
isHapticFeedbackEnabled() |
boolean |
isHardwareAccelerated()
Indicates whether this view is attached to a hardware accelerated
window or not.
|
boolean |
isHorizontalFadingEdgeEnabled()
Indicate whether the horizontal edges are faded when the view is
scrolled horizontally.
|
boolean |
isHorizontalScrollBarEnabled()
Indicate whether the horizontal scrollbar should be drawn or not.
|
boolean |
isHovered()
Returns true if the view is currently hovered.
|
boolean |
isImportantForAccessibility()
Computes whether this view should be exposed for accessibility.
|
boolean |
isInEditMode()
Indicates whether this View is currently in edit mode.
|
boolean |
isInLayout()
Returns whether the view hierarchy is currently undergoing a layout pass.
|
boolean |
isInScrollingContainer() |
boolean |
isInTouchMode()
Returns whether the device is currently in touch mode.
|
boolean |
isLaidOut()
Returns true if this view has been through at least one layout since it
was last attached to or detached from a window.
|
boolean |
isLayoutDirectionInherited() |
boolean |
isLayoutDirectionResolved() |
static boolean |
isLayoutModeOptical(Object o)
Return true if o is a ViewGroup that is laying out using optical bounds.
|
boolean |
isLayoutRequested()
Indicates whether or not this view's layout will be requested during
the next hierarchy layout pass.
|
boolean |
isLayoutRtl()
Indicates whether or not this view's layout is right-to-left.
|
boolean |
isLongClickable()
Indicates whether this view reacts to long click events or not.
|
boolean |
isNestedScrollingEnabled()
Returns true if nested scrolling is enabled for this view.
|
boolean |
isOpaque()
Indicates whether this View is opaque.
|
protected boolean |
isPaddingOffsetRequired()
If the View draws content inside its padding and enables fading edges,
it needs to support padding offsets.
|
boolean |
isPaddingRelative()
Return if the padding has been set through relative values
setPaddingRelative(int, int, int, int) or through |
boolean |
isPressed()
Indicates whether the view is currently in pressed state.
|
boolean |
isRootNamespace() |
boolean |
isSaveEnabled()
Indicates whether this view will save its state (that is,
whether its
onSaveInstanceState() method will be called). |
boolean |
isSaveFromParentEnabled()
Indicates whether the entire hierarchy under this view will save its
state when a state saving traversal occurs from its parent.
|
boolean |
isScrollbarFadingEnabled()
Returns true if scrollbars will fade when this view is not scrolling
|
boolean |
isScrollContainer()
Indicates whether this view is one of the set of scrollable containers in
its window.
|
boolean |
isSelected()
Indicates the selection state of this view.
|
boolean |
isShown()
Returns the visibility of this view and all of its ancestors
|
boolean |
isSoundEffectsEnabled() |
boolean |
isTemporarilyDetached()
Tells whether the
View is in the state between onStartTemporaryDetach()
and onFinishTemporaryDetach() . |
boolean |
isTextAlignmentInherited() |
boolean |
isTextAlignmentResolved() |
boolean |
isTextDirectionInherited() |
boolean |
isTextDirectionResolved() |
boolean |
isVerticalFadingEdgeEnabled()
Indicate whether the vertical edges are faded when the view is
scrolled horizontally.
|
boolean |
isVerticalScrollBarEnabled()
Indicate whether the vertical scrollbar should be drawn or not.
|
protected boolean |
isVerticalScrollBarHidden()
Override this if the vertical scrollbar needs to be hidden in a subclass, like when
FastScroller is visible.
|
protected boolean |
isVisibleToUser()
Computes whether this view is visible to the user.
|
protected boolean |
isVisibleToUser(Rect boundInView)
Computes whether the given portion of this view is visible to the user.
|
void |
jumpDrawablesToCurrentState()
Call
Drawable.jumpToCurrentState()
on all Drawable objects associated with this view. |
void |
layout(int l,
int t,
int r,
int b)
Assign a size and position to a view and all of its
descendants
This is the second phase of the layout mechanism.
|
void |
makeOptionalFitsSystemWindows()
For use by PhoneWindow to make its own system window fitting optional.
|
void |
measure(int widthMeasureSpec,
int heightMeasureSpec)
This is called to find out how big a view should be.
|
protected static int[] |
mergeDrawableStates(int[] baseState,
int[] additionalState)
Merge your own state values in additionalState into the base
state values baseState that were returned by
onCreateDrawableState(int) . |
void |
notifySubtreeAccessibilityStateChangedIfNeeded()
Notifies that the accessibility state of this view changed.
|
void |
notifyViewAccessibilityStateChangedIfNeeded(int changeType)
Notifies that the accessibility state of this view changed.
|
void |
offsetLeftAndRight(int offset)
Offset this view's horizontal location by the specified amount of pixels.
|
void |
offsetTopAndBottom(int offset)
Offset this view's vertical location by the specified number of pixels.
|
void |
onActivityResult(int requestCode,
int resultCode,
Intent data)
Receive the result from a previous call to
startActivityForResult(Intent, int) . |
protected void |
onAnimationEnd()
Invoked by a parent ViewGroup to notify the end of the animation
currently associated with this view.
|
protected void |
onAnimationStart()
Invoked by a parent ViewGroup to notify the start of the animation
currently associated with this view.
|
WindowInsets |
onApplyWindowInsets(WindowInsets insets)
Called when the view should apply
WindowInsets according to its internal policy. |
protected void |
onAttachedToWindow()
This is called when the view is attached to a window.
|
void |
onCancelPendingInputEvents()
Called as the result of a call to
cancelPendingInputEvents() on this view or
a parent view. |
boolean |
onCheckIsTextEditor()
Check whether the called view is a text editor, in which case it
would make sense to automatically display a soft input window for
it.
|
void |
onCloseSystemDialogs(String reason)
This needs to be a better API (NOT ON VIEW) before it is exposed.
|
protected void |
onConfigurationChanged(Configuration newConfig)
Called when the current configuration of the resources being used
by the application have changed.
|
protected void |
onCreateContextMenu(ContextMenu menu)
Views should implement this if the view itself is going to add items to
the context menu.
|
protected int[] |
onCreateDrawableState(int extraSpace)
Generate the new
Drawable state for
this view. |
InputConnection |
onCreateInputConnection(EditorInfo outAttrs)
Create a new InputConnection for an InputMethod to interact
with the view.
|
protected void |
onDetachedFromWindow()
This is called when the view is detached from a window.
|
protected void |
onDetachedFromWindowInternal()
This is a framework-internal mirror of onDetachedFromWindow() that's called
after onDetachedFromWindow().
|
protected void |
onDisplayHint(int hint)
Gives this view a hint about whether is displayed or not.
|
boolean |
onDragEvent(DragEvent event)
Handles drag events sent by the system following a call to
startDragAndDrop() . |
protected void |
onDraw(Canvas canvas)
Implement this to do your drawing.
|
void |
onDrawForeground(Canvas canvas)
Draw any foreground content for this view.
|
protected void |
onDrawHorizontalScrollBar(Canvas canvas,
Drawable scrollBar,
int l,
int t,
int r,
int b)
Draw the horizontal scrollbar if
isHorizontalScrollBarEnabled() returns true. |
protected void |
onDrawScrollBars(Canvas canvas)
Request the drawing of the horizontal and the vertical scrollbar.
|
protected void |
onDrawVerticalScrollBar(Canvas canvas,
Drawable scrollBar,
int l,
int t,
int r,
int b)
Draw the vertical scrollbar if
isVerticalScrollBarEnabled()
returns true. |
boolean |
onFilterTouchEventForSecurity(MotionEvent event)
Filter the touch event to apply security policies.
|
protected void |
onFinishInflate()
Finalize inflating a view from XML.
|
void |
onFinishTemporaryDetach()
Called after
onStartTemporaryDetach() when the container is done
changing the view. |
protected void |
onFocusChanged(boolean gainFocus,
int direction,
Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
|
protected void |
onFocusLost()
Invoked whenever this view loses focus, either by losing window focus or by losing
focus within its window.
|
boolean |
onGenericMotionEvent(MotionEvent event)
Implement this method to handle generic motion events.
|
void |
onHoverChanged(boolean hovered)
Implement this method to handle hover state changes.
|
boolean |
onHoverEvent(MotionEvent event)
Implement this method to handle hover events.
|
void |
onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an
AccessibilityEvent with information about
this View which is the event source. |
void |
onInitializeAccessibilityEventInternal(AccessibilityEvent event) |
void |
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an
AccessibilityNodeInfo with information about this view. |
void |
onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) |
boolean |
onKeyDown(int keyCode,
KeyEvent event)
Default implementation of
KeyEvent.Callback.onKeyDown() : perform press of the view
when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER
is released, if the view is enabled and clickable. |
boolean |
onKeyLongPress(int keyCode,
KeyEvent event)
Default implementation of
KeyEvent.Callback.onKeyLongPress() : always returns false (doesn't handle
the event). |
boolean |
onKeyMultiple(int keyCode,
int repeatCount,
KeyEvent event)
Default implementation of
KeyEvent.Callback.onKeyMultiple() : always returns false (doesn't handle
the event). |
boolean |
onKeyPreIme(int keyCode,
KeyEvent event)
Handle a key event before it is processed by any input method
associated with the view hierarchy.
|
boolean |
onKeyShortcut(int keyCode,
KeyEvent event)
Called on the focused view when a key shortcut event is not handled.
|
boolean |
onKeyUp(int keyCode,
KeyEvent event)
Default implementation of
KeyEvent.Callback.onKeyUp() : perform clicking of the view
when KeyEvent.KEYCODE_DPAD_CENTER , KeyEvent.KEYCODE_ENTER
or KeyEvent.KEYCODE_SPACE is released. |
protected void |
onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
Called from layout when this view should
assign a size and position to each of its children.
|
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height.
|
protected void |
onOverScrolled(int scrollX,
int scrollY,
boolean clampedX,
boolean clampedY)
Called by
overScrollBy(int, int, int, int, int, int, int, int, boolean) to
respond to the results of an over-scroll operation. |
void |
onPopulateAccessibilityEvent(AccessibilityEvent event)
Called from
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
giving a chance to this View to populate the accessibility event with its
text content. |
void |
onPopulateAccessibilityEventInternal(AccessibilityEvent event) |
void |
onProvideStructure(ViewStructure structure)
Called when assist structure is being retrieved from a view as part of
Activity.onProvideAssistData . |
void |
onProvideVirtualStructure(ViewStructure structure)
Called when assist structure is being retrieved from a view as part of
Activity.onProvideAssistData to
generate additional virtual structure under this view. |
void |
onRenderNodeDetached(RenderNode renderNode)
Called when the passed RenderNode is removed from the draw tree
|
void |
onResolveDrawables(int layoutDirection)
Called when layout direction has been resolved.
|
PointerIcon |
onResolvePointerIcon(MotionEvent event,
int pointerIndex)
Returns the pointer icon for the motion event, or null if it doesn't specify the icon.
|
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by
onSaveInstanceState() . |
void |
onRtlPropertiesChanged(int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has
been changed.
|
protected Parcelable |
onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state
that can later be used to create a new instance with that same state.
|
void |
onScreenStateChanged(int screenState)
This method is called whenever the state of the screen this view is
attached to changes.
|
protected void |
onScrollChanged(int l,
int t,
int oldl,
int oldt)
This is called in response to an internal scroll in this view (i.e., the
view scrolled its own contents).
|
protected boolean |
onSetAlpha(int alpha)
Invoked if there is a Transform that involves alpha.
|
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed.
|
void |
onStartTemporaryDetach()
This is called when a container is going to temporarily detach a child, with
ViewGroup.detachViewFromParent . |
boolean |
onTouchEvent(MotionEvent event)
Implement this method to handle touch screen motion events.
|
boolean |
onTrackballEvent(MotionEvent event)
Implement this method to handle trackball motion events.
|
void |
onVisibilityAggregated(boolean isVisible)
Called when the user-visibility of this View is potentially affected by a change
to this view itself, an ancestor view or the window this view is attached to.
|
protected void |
onVisibilityChanged(View changedView,
int visibility)
Called when the visibility of the view or an ancestor of the view has
changed.
|
void |
onWindowFocusChanged(boolean hasWindowFocus)
Called when the window containing this view gains or loses focus.
|
void |
onWindowSystemUiVisibilityChanged(int visible)
Override to find out when the window's requested system UI visibility
has changed, that is the value returned by
getWindowSystemUiVisibility() . |
protected void |
onWindowVisibilityChanged(int visibility)
|
void |
outputDirtyFlags(String indent,
boolean clear,
int clearMask)
Debugging utility which recursively outputs the dirty state of a view and its
descendants.
|
protected boolean |
overScrollBy(int deltaX,
int deltaY,
int scrollX,
int scrollY,
int scrollRangeX,
int scrollRangeY,
int maxOverScrollX,
int maxOverScrollY,
boolean isTouchEvent)
Scroll the view with standard behavior for scrolling beyond the normal
content boundaries.
|
boolean |
performAccessibilityAction(int action,
Bundle arguments)
Performs the specified accessibility action on the view.
|
boolean |
performAccessibilityActionInternal(int action,
Bundle arguments) |
protected boolean |
performButtonActionOnTouchDown(MotionEvent event)
Performs button-related actions during a touch down event.
|
boolean |
performClick()
Call this view's OnClickListener, if it is defined.
|
boolean |
performContextClick()
Call this view's OnContextClickListener, if it is defined.
|
boolean |
performContextClick(float x,
float y)
Call this view's OnContextClickListener, if it is defined.
|
boolean |
performHapticFeedback(int feedbackConstant)
BZZZTT!!
|
boolean |
performHapticFeedback(int feedbackConstant,
int flags)
BZZZTT!!
|
boolean |
performLongClick()
Calls this view's OnLongClickListener, if it is defined.
|
boolean |
performLongClick(float x,
float y)
Calls this view's OnLongClickListener, if it is defined.
|
void |
playSoundEffect(int soundConstant)
Play a sound effect for this view.
|
boolean |
pointInView(float localX,
float localY,
float slop)
Utility method to determine whether the given point, in local coordinates,
is inside the view, where the area of the view is expanded by the slop factor.
|
boolean |
post(Runnable action)
Causes the Runnable to be added to the message queue.
|
boolean |
postDelayed(Runnable action,
long delayMillis)
Causes the Runnable to be added to the message queue, to be run
after the specified amount of time elapses.
|
void |
postInvalidate()
Cause an invalidate to happen on a subsequent cycle through the event loop.
|
void |
postInvalidate(int left,
int top,
int right,
int bottom)
Cause an invalidate of the specified area to happen on a subsequent cycle
through the event loop.
|
void |
postInvalidateDelayed(long delayMilliseconds)
Cause an invalidate to happen on a subsequent cycle through the event
loop.
|
void |
postInvalidateDelayed(long delayMilliseconds,
int left,
int top,
int right,
int bottom)
Cause an invalidate of the specified area to happen on a subsequent cycle
through the event loop.
|
void |
postInvalidateOnAnimation()
Cause an invalidate to happen on the next animation time step, typically the
next display frame.
|
void |
postInvalidateOnAnimation(int left,
int top,
int right,
int bottom)
Cause an invalidate of the specified area to happen on the next animation
time step, typically the next display frame.
|
void |
postOnAnimation(Runnable action)
Causes the Runnable to execute on the next animation time step.
|
void |
postOnAnimationDelayed(Runnable action,
long delayMillis)
Causes the Runnable to execute on the next animation time step,
after the specified amount of time elapses.
|
protected void |
recomputePadding() |
void |
refreshDrawableState()
Call this to force a view to update its drawable state.
|
boolean |
removeCallbacks(Runnable action)
Removes the specified Runnable from the message queue.
|
void |
removeFrameMetricsListener(Window.OnFrameMetricsAvailableListener listener)
Remove observer configured to collect frame stats for this view.
|
void |
removeOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)
Remove a listener for attach state changes.
|
void |
removeOnLayoutChangeListener(View.OnLayoutChangeListener listener)
Remove a listener for layout changes.
|
boolean |
requestAccessibilityFocus()
Call this to try to give accessibility focus to this view.
|
void |
requestApplyInsets()
Ask that a new dispatch of
onApplyWindowInsets(WindowInsets) be performed. |
void |
requestFitSystemWindows()
Deprecated.
Use
requestApplyInsets() for newer platform versions. |
boolean |
requestFocus()
Call this to try to give focus to a specific view or to one of its
descendants.
|
boolean |
requestFocus(int direction)
Call this to try to give focus to a specific view or to one of its
descendants and give it a hint about what direction focus is heading.
|
boolean |
requestFocus(int direction,
Rect previouslyFocusedRect)
Call this to try to give focus to a specific view or to one of its descendants
and give it hints about the direction and a specific rectangle that the focus
is coming from.
|
boolean |
requestFocusFromTouch()
Call this to try to give focus to a specific view or to one of its descendants.
|
void |
requestKeyboardShortcuts(List<KeyboardShortcutGroup> data,
int deviceId) |
void |
requestLayout()
Call this when something has changed which has invalidated the
layout of this view.
|
boolean |
requestRectangleOnScreen(Rect rectangle)
Request that a rectangle of this view be visible on the screen,
scrolling if necessary just enough.
|
boolean |
requestRectangleOnScreen(Rect rectangle,
boolean immediate)
Request that a rectangle of this view be visible on the screen,
scrolling if necessary just enough.
|
void |
requestUnbufferedDispatch(MotionEvent event)
Request unbuffered dispatch of the given stream of MotionEvents to this View.
|
void |
resetPaddingToInitialValues() |
protected void |
resetResolvedDrawables() |
void |
resetResolvedLayoutDirection()
Reset the resolved layout direction.
|
void |
resetResolvedPadding()
Reset the resolved layout direction.
|
void |
resetResolvedTextAlignment()
Reset resolved text alignment.
|
void |
resetResolvedTextDirection()
Reset resolved text direction.
|
void |
resetRtlProperties()
Reset resolution of all RTL related properties.
|
protected void |
resolveDrawables()
Resolve the Drawables depending on the layout direction.
|
boolean |
resolveLayoutDirection()
Resolve and cache the layout direction.
|
void |
resolveLayoutParams()
Resolve the layout parameters depending on the resolved layout direction
|
void |
resolvePadding()
Resolves padding depending on layout direction, if applicable, and
recomputes internal padding values to adjust for scroll bars.
|
boolean |
resolveRtlPropertiesIfNeeded()
Resolve all RTL related properties.
|
static int |
resolveSize(int size,
int measureSpec)
Version of
resolveSizeAndState(int, int, int)
returning only the MEASURED_SIZE_MASK bits of the result. |
static int |
resolveSizeAndState(int size,
int measureSpec,
int childMeasuredState)
Utility to reconcile a desired size and state, with constraints imposed
by a MeasureSpec.
|
boolean |
resolveTextAlignment()
Resolve the text alignment.
|
boolean |
resolveTextDirection()
Resolve the text direction.
|
void |
restoreHierarchyState(SparseArray<Parcelable> container)
Restore this view hierarchy's frozen state from the given container.
|
void |
saveHierarchyState(SparseArray<Parcelable> container)
Store this view hierarchy's frozen state into the given container.
|
void |
scheduleDrawable(Drawable who,
Runnable what,
long when)
Schedules an action on a drawable to occur at a specified time.
|
void |
scrollBy(int x,
int y)
Move the scrolled position of your view.
|
void |
scrollTo(int x,
int y)
Set the scrolled position of your view.
|
void |
sendAccessibilityEvent(int eventType)
Sends an accessibility event of the given type.
|
void |
sendAccessibilityEventInternal(int eventType) |
void |
sendAccessibilityEventUnchecked(AccessibilityEvent event)
This method behaves exactly as
sendAccessibilityEvent(int) but
takes as an argument an empty AccessibilityEvent and does not
perform a check whether accessibility is enabled. |
void |
sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) |
void |
setAccessibilityDelegate(View.AccessibilityDelegate delegate)
Sets a delegate for implementing accessibility support via composition
(as opposed to inheritance).
|
void |
setAccessibilityLiveRegion(int mode)
Sets the live region mode for this view.
|
void |
setAccessibilitySelection(int start,
int end) |
void |
setAccessibilityTraversalAfter(int afterId)
Sets the id of a view after which this one is visited in accessibility traversal.
|
void |
setAccessibilityTraversalBefore(int beforeId)
Sets the id of a view before which this one is visited in accessibility traversal.
|
void |
setActivated(boolean activated)
Changes the activated state of this view.
|
void |
setAlpha(float alpha)
Sets the opacity of the view to a value from 0 to 1, where 0 means the view is
completely transparent and 1 means the view is completely opaque.
|
void |
setAnimation(Animation animation)
Sets the next animation to play for this view.
|
void |
setAnimationMatrix(Matrix matrix) |
void |
setAssistBlocked(boolean enabled) |
void |
setBackground(Drawable background)
Set the background to a given Drawable, or remove the background.
|
void |
setBackgroundColor(int color)
Sets the background color for this view.
|
void |
setBackgroundDrawable(Drawable background)
Deprecated.
use
setBackground(Drawable) instead |
void |
setBackgroundResource(int resid)
Set the background to a given resource.
|
void |
setBackgroundTintList(ColorStateList tint)
Applies a tint to the background drawable.
|
void |
setBackgroundTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by
setBackgroundTintList(ColorStateList) } to the background
drawable. |
void |
setBottom(int bottom)
Sets the bottom position of this view relative to its parent.
|
void |
setCameraDistance(float distance)
Sets the distance along the Z axis (orthogonal to the X/Y plane on which
views are drawn) from the camera to this view.
|
void |
setClickable(boolean clickable)
Enables or disables click events for this view.
|
void |
setClipBounds(Rect clipBounds)
Sets a rectangular area on this view to which the view will be clipped
when it is drawn.
|
void |
setClipToOutline(boolean clipToOutline)
Sets whether the View's Outline should be used to clip the contents of the View.
|
void |
setContentDescription(CharSequence contentDescription)
Sets the
View 's content description. |
void |
setContextClickable(boolean contextClickable)
Enables or disables context clicking for this view.
|
void |
setDisabledSystemUiVisibility(int flags) |
void |
setDrawingCacheBackgroundColor(int color)
Setting a solid background color for the drawing cache's bitmaps will improve
performance and memory usage.
|
void |
setDrawingCacheEnabled(boolean enabled)
Enables or disables the drawing cache.
|
void |
setDrawingCacheQuality(int quality)
Set the drawing cache quality of this view.
|
void |
setDuplicateParentStateEnabled(boolean enabled)
Enables or disables the duplication of the parent's state into this view.
|
void |
setElevation(float elevation)
Sets the base elevation of this view, in pixels.
|
void |
setEnabled(boolean enabled)
Set the enabled state of this view.
|
void |
setFadingEdgeLength(int length)
Set the size of the faded edge used to indicate that more content in this
view is available.
|
void |
setFilterTouchesWhenObscured(boolean enabled)
Sets whether the framework should discard touches when the view's
window is obscured by another visible window.
|
void |
setFitsSystemWindows(boolean fitSystemWindows)
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. |
void |
setFocusable(boolean focusable)
Set whether this view can receive the focus.
|
void |
setFocusableInTouchMode(boolean focusableInTouchMode)
Set whether this view can receive focus while in touch mode.
|
void |
setForeground(Drawable foreground)
Supply a Drawable that is to be rendered on top of all of the content in the view.
|
void |
setForegroundGravity(int gravity)
Describes how the foreground is positioned.
|
void |
setForegroundTintList(ColorStateList tint)
Applies a tint to the foreground drawable.
|
void |
setForegroundTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by
setForegroundTintList(ColorStateList) } to the background
drawable. |
protected boolean |
setFrame(int left,
int top,
int right,
int bottom)
Assign a size and position to this view.
|
void |
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
Set whether this view should have haptic feedback for events such as
long presses.
|
void |
setHasTransientState(boolean hasTransientState)
Set whether this view is currently tracking transient state that the
framework should attempt to preserve when possible.
|
void |
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
Define whether the horizontal edges should be faded when this view
is scrolled horizontally.
|
void |
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
Define whether the horizontal scrollbar should be drawn or not.
|
void |
setHovered(boolean hovered)
Sets whether the view is currently hovered.
|
void |
setId(int id)
Sets the identifier for this view.
|
void |
setImportantForAccessibility(int mode)
Sets how to determine whether this view is important for accessibility
which is if it fires accessibility events and if it is reported to
accessibility services that query the screen.
|
void |
setIsRootNamespace(boolean isRoot) |
void |
setKeepScreenOn(boolean keepScreenOn)
Controls whether the screen should remain on, modifying the
value of
KEEP_SCREEN_ON . |
void |
setLabelFor(int id)
Sets the id of a view for which this view serves as a label for
accessibility purposes.
|
void |
setLayerPaint(Paint paint)
Updates the
Paint object used with the current layer (used only if the current
layer type is not set to LAYER_TYPE_NONE ). |
void |
setLayerType(int layerType,
Paint paint)
Specifies the type of layer backing this view.
|
void |
setLayoutDirection(int layoutDirection)
Set the layout direction for this view.
|
void |
setLayoutParams(ViewGroup.LayoutParams params)
Set the layout parameters associated with this view.
|
void |
setLeft(int left)
Sets the left position of this view relative to its parent.
|
void |
setLeftTopRightBottom(int left,
int top,
int right,
int bottom)
Same as setFrame, but public and hidden.
|
void |
setLongClickable(boolean longClickable)
Enables or disables long click events for this view.
|
protected void |
setMeasuredDimension(int measuredWidth,
int measuredHeight)
This method must be called by
onMeasure(int, int) to store the
measured width and measured height. |
void |
setMinimumHeight(int minHeight)
Sets the minimum height of the view.
|
void |
setMinimumWidth(int minWidth)
Sets the minimum width of the view.
|
void |
setNestedScrollingEnabled(boolean enabled)
Enable or disable nested scrolling for this view.
|
void |
setNextFocusDownId(int nextFocusDownId)
Sets the id of the view to use when the next focus is
FOCUS_DOWN . |
void |
setNextFocusForwardId(int nextFocusForwardId)
Sets the id of the view to use when the next focus is
FOCUS_FORWARD . |
void |
setNextFocusLeftId(int nextFocusLeftId)
Sets the id of the view to use when the next focus is
FOCUS_LEFT . |
void |
setNextFocusRightId(int nextFocusRightId)
Sets the id of the view to use when the next focus is
FOCUS_RIGHT . |
void |
setNextFocusUpId(int nextFocusUpId)
Sets the id of the view to use when the next focus is
FOCUS_UP . |
void |
setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
Set an
View.OnApplyWindowInsetsListener to take over the policy for applying
window insets to this view. |
void |
setOnClickListener(View.OnClickListener l)
Register a callback to be invoked when this view is clicked.
|
void |
setOnContextClickListener(View.OnContextClickListener l)
Register a callback to be invoked when this view is context clicked.
|
void |
setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)
Register a callback to be invoked when the context menu for this view is
being built.
|
void |
setOnDragListener(View.OnDragListener l)
Register a drag event listener callback object for this View.
|
void |
setOnFocusChangeListener(View.OnFocusChangeListener l)
Register a callback to be invoked when focus of this view changed.
|
void |
setOnGenericMotionListener(View.OnGenericMotionListener l)
Register a callback to be invoked when a generic motion event is sent to this view.
|
void |
setOnHoverListener(View.OnHoverListener l)
Register a callback to be invoked when a hover event is sent to this view.
|
void |
setOnKeyListener(View.OnKeyListener l)
Register a callback to be invoked when a hardware key is pressed in this view.
|
void |
setOnLongClickListener(View.OnLongClickListener l)
Register a callback to be invoked when this view is clicked and held.
|
void |
setOnScrollChangeListener(View.OnScrollChangeListener l)
Register a callback to be invoked when the scroll X or Y positions of
this view change.
|
void |
setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener l)
Set a listener to receive callbacks when the visibility of the system bar changes.
|
void |
setOnTouchListener(View.OnTouchListener l)
Register a callback to be invoked when a touch event is sent to this view.
|
void |
setOpticalInsets(Insets insets)
Set this view's optical insets.
|
void |
setOutlineProvider(ViewOutlineProvider provider)
Sets the
ViewOutlineProvider of the view, which generates the Outline that defines
the shape of the shadow it casts, and enables outline clipping. |
void |
setOverScrollMode(int overScrollMode)
Set the over-scroll mode for this view.
|
void |
setPadding(int left,
int top,
int right,
int bottom)
Sets the padding.
|
void |
setPaddingRelative(int start,
int top,
int end,
int bottom)
Sets the relative padding.
|
void |
setPivotX(float pivotX)
|
void |
setPivotY(float pivotY)
|
void |
setPointerIcon(PointerIcon pointerIcon)
Set the pointer icon for the current view.
|
void |
setPressed(boolean pressed)
Sets the pressed state for this view.
|
void |
setRevealClip(boolean shouldClip,
float x,
float y,
float radius) |
void |
setRevealOnFocusHint(boolean revealOnFocus)
Sets this view's preference for reveal behavior when it gains focus.
|
void |
setRight(int right)
Sets the right position of this view relative to its parent.
|
void |
setRotation(float rotation)
Sets the degrees that the view is rotated around the pivot point.
|
void |
setRotationX(float rotationX)
Sets the degrees that the view is rotated around the horizontal axis through the pivot point.
|
void |
setRotationY(float rotationY)
Sets the degrees that the view is rotated around the vertical axis through the pivot point.
|
void |
setSaveEnabled(boolean enabled)
Controls whether the saving of this view's state is
enabled (that is, whether its
onSaveInstanceState() method
will be called). |
void |
setSaveFromParentEnabled(boolean enabled)
Controls whether the entire hierarchy under this view will save its
state when a state saving traversal occurs from its parent.
|
void |
setScaleX(float scaleX)
Sets the amount that the view is scaled in x around the pivot point, as a proportion of
the view's unscaled width.
|
void |
setScaleY(float scaleY)
Sets the amount that the view is scaled in Y around the pivot point, as a proportion of
the view's unscaled width.
|
void |
setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade)
Define the delay before scrollbars fade.
|
void |
setScrollBarFadeDuration(int scrollBarFadeDuration)
Define the scrollbar fade duration.
|
void |
setScrollbarFadingEnabled(boolean fadeScrollbars)
Define whether scrollbars will fade when the view is not scrolling.
|
void |
setScrollBarSize(int scrollBarSize)
Define the scrollbar size.
|
void |
setScrollBarStyle(int style)
Specify the style of the scrollbars.
|
void |
setScrollContainer(boolean isScrollContainer)
Change whether this view is one of the set of scrollable containers in
its window.
|
void |
setScrollIndicators(int indicators)
Sets the state of all scroll indicators.
|
void |
setScrollIndicators(int indicators,
int mask)
Sets the state of the scroll indicators specified by the mask.
|
void |
setScrollX(int value)
Set the horizontal scrolled position of your view.
|
void |
setScrollY(int value)
Set the vertical scrolled position of your view.
|
void |
setSelected(boolean selected)
Changes the selection state of this view.
|
void |
setSoundEffectsEnabled(boolean soundEffectsEnabled)
Set whether this view should have sound effects enabled for events such as
clicking and touching.
|
void |
setStateListAnimator(StateListAnimator stateListAnimator)
Attaches the provided StateListAnimator to this View.
|
void |
setSystemUiVisibility(int visibility)
Request that the visibility of the status bar or other screen/window
decorations be changed.
|
void |
setTag(int key,
Object tag)
Sets a tag associated with this view and a key.
|
void |
setTag(Object tag)
Sets the tag associated with this view.
|
void |
setTagInternal(int key,
Object tag)
Variation of
setTag(int, Object) that enforces the key to be a
framework id. |
void |
setTextAlignment(int textAlignment)
Set the text alignment.
|
void |
setTextDirection(int textDirection)
Set the text direction.
|
void |
setTop(int top)
Sets the top position of this view relative to its parent.
|
void |
setTouchDelegate(TouchDelegate delegate)
Sets the TouchDelegate for this View.
|
void |
setTransitionAlpha(float alpha)
This property is hidden and intended only for use by the Fade transition, which
animates it to produce a visual translucency that does not side-effect (or get
affected by) the real alpha property.
|
void |
setTransitionName(String transitionName)
Sets the name of the View to be used to identify Views in Transitions.
|
void |
setTransitionVisibility(int visibility)
Change the visibility of the View without triggering any other changes.
|
void |
setTranslationX(float translationX)
Sets the horizontal location of this view relative to its
left position. |
void |
setTranslationY(float translationY)
Sets the vertical location of this view relative to its
top position. |
void |
setTranslationZ(float translationZ)
Sets the depth location of this view relative to its
elevation . |
void |
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
Define whether the vertical edges should be faded when this view
is scrolled vertically.
|
void |
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
Define whether the vertical scrollbar should be drawn or not.
|
void |
setVerticalScrollbarPosition(int position)
Set the position of the vertical scroll bar.
|
void |
setVisibility(int visibility)
Set the visibility state of this view.
|
void |
setWillNotCacheDrawing(boolean willNotCacheDrawing)
When a View's drawing cache is enabled, drawing is redirected to an
offscreen bitmap.
|
void |
setWillNotDraw(boolean willNotDraw)
If this view doesn't do any drawing on its own, set this flag to
allow further optimizations.
|
void |
setX(float x)
Sets the visual x position of this view, in pixels.
|
void |
setY(float y)
Sets the visual y position of this view, in pixels.
|
void |
setZ(float z)
Sets the visual z position of this view, in pixels.
|
boolean |
showContextMenu()
Shows the context menu for this view.
|
boolean |
showContextMenu(float x,
float y)
Shows the context menu for this view anchored to the specified
view-relative coordinate.
|
ActionMode |
startActionMode(ActionMode.Callback callback)
Start an action mode with the default type
ActionMode.TYPE_PRIMARY . |
ActionMode |
startActionMode(ActionMode.Callback callback,
int type)
Start an action mode with the given type.
|
void |
startActivityForResult(Intent intent,
int requestCode)
Call
Context.startActivityForResult(String, Intent, int, Bundle) for the View's
Context, creating a unique View identifier to retrieve the result. |
void |
startAnimation(Animation animation)
Start the specified animation now.
|
boolean |
startDrag(ClipData data,
View.DragShadowBuilder shadowBuilder,
Object myLocalState,
int flags)
Deprecated.
Use
startDragAndDrop() for newer platform versions. |
boolean |
startDragAndDrop(ClipData data,
View.DragShadowBuilder shadowBuilder,
Object myLocalState,
int flags)
Starts a drag and drop operation.
|
boolean |
startMovingTask(float startX,
float startY)
Starts a move from {startX, startY}, the amount of the movement will be the offset
between {startX, startY} and the new cursor positon.
|
boolean |
startNestedScroll(int axes)
Begin a nestable scroll operation along the given axes.
|
void |
stopNestedScroll()
Stop a nested scroll in progress.
|
boolean |
toGlobalMotionEvent(MotionEvent ev)
Transforms a motion event from view-local coordinates to on-screen
coordinates.
|
boolean |
toLocalMotionEvent(MotionEvent ev)
Transforms a motion event from on-screen coordinates to view-local
coordinates.
|
String |
toString()
Returns a string representation of the object.
|
void |
transformFromViewToWindowSpace(int[] inOutLocation) |
void |
transformMatrixToGlobal(Matrix m)
Modifies the input matrix such that it maps view-local coordinates to
on-screen coordinates.
|
void |
transformMatrixToLocal(Matrix m)
Modifies the input matrix such that it maps on-screen coordinates to
view-local coordinates.
|
void |
unscheduleDrawable(Drawable who)
Unschedule any events associated with the given Drawable.
|
void |
unscheduleDrawable(Drawable who,
Runnable what)
Cancels a scheduled action on a drawable.
|
RenderNode |
updateDisplayListIfDirty()
Gets the RenderNode for the view, and updates its DisplayList (if needed and supported)
|
void |
updateDragShadow(View.DragShadowBuilder shadowBuilder)
Updates the drag shadow for the ongoing drag and drop operation.
|
protected boolean |
verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should
override this function and return true for any Drawable it is
displaying.
|
boolean |
willNotCacheDrawing()
Returns whether or not this View can cache its drawing or not.
|
boolean |
willNotDraw()
Returns whether or not this View draws on its own.
|
protected static final String VIEW_LOG_TAG
public static final String DEBUG_LAYOUT_PROPERTY
public static boolean mDebugViewAttributes
public static final int NO_ID
protected static boolean sPreserveMarginParamsInLayoutParamConversion
public static final int VISIBLE
setVisibility(int)
and android:visibility
.public static final int INVISIBLE
setVisibility(int)
and android:visibility
.public static final int GONE
setVisibility(int)
and android:visibility
.public static final int DRAWING_CACHE_QUALITY_LOW
Enables low quality mode for the drawing cache.
public static final int DRAWING_CACHE_QUALITY_HIGH
Enables high quality mode for the drawing cache.
public static final int DRAWING_CACHE_QUALITY_AUTO
Enables automatic quality mode for the drawing cache.
public static final int SCROLLBARS_INSIDE_OVERLAY
public static final int SCROLLBARS_INSIDE_INSET
public static final int SCROLLBARS_OUTSIDE_OVERLAY
public static final int SCROLLBARS_OUTSIDE_INSET
public static final int KEEP_SCREEN_ON
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
.public static final int SOUND_EFFECTS_ENABLED
public static final int HAPTIC_FEEDBACK_ENABLED
public static final int FOCUSABLES_ALL
addFocusables(ArrayList, int, int)
should add all focusable Views regardless if they are focusable in touch mode.public static final int FOCUSABLES_TOUCH_MODE
addFocusables(ArrayList, int, int)
should add only Views focusable in touch mode.public static final int FOCUS_BACKWARD
focusSearch(int)
. Move focus to the previous selectable
item.public static final int FOCUS_FORWARD
focusSearch(int)
. Move focus to the next selectable
item.public static final int FOCUS_LEFT
focusSearch(int)
. Move focus to the left.public static final int FOCUS_UP
focusSearch(int)
. Move focus up.public static final int FOCUS_RIGHT
focusSearch(int)
. Move focus to the right.public static final int FOCUS_DOWN
focusSearch(int)
. Move focus down.public static final int MEASURED_SIZE_MASK
getMeasuredWidthAndState()
and
getMeasuredWidthAndState()
that provide the actual measured size.public static final int MEASURED_STATE_MASK
getMeasuredWidthAndState()
and
getMeasuredWidthAndState()
that provide the additional state bits.public static final int MEASURED_HEIGHT_STATE_SHIFT
MEASURED_STATE_MASK
to get to the height bits
for functions that combine both width and height into a single int,
such as getMeasuredState()
and the childState argument of
resolveSizeAndState(int, int, int)
.public static final int MEASURED_STATE_TOO_SMALL
getMeasuredWidthAndState()
and
getMeasuredWidthAndState()
that indicates the measured size
is smaller that the space the view would like to have.protected static final int[] EMPTY_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] ENABLED_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] FOCUSED_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] SELECTED_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] PRESSED_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] WINDOW_FOCUSED_STATE_SET
Drawable
to change the drawing of the
view depending on its state.Drawable
,
getDrawableState()
protected static final int[] ENABLED_FOCUSED_STATE_SET
ENABLED_STATE_SET
,
FOCUSED_STATE_SET
protected static final int[] ENABLED_SELECTED_STATE_SET
ENABLED_STATE_SET
,
SELECTED_STATE_SET
protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET
ENABLED_STATE_SET
,
WINDOW_FOCUSED_STATE_SET
protected static final int[] FOCUSED_SELECTED_STATE_SET
FOCUSED_STATE_SET
,
SELECTED_STATE_SET
protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET
FOCUSED_STATE_SET
,
WINDOW_FOCUSED_STATE_SET
protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET
SELECTED_STATE_SET
,
WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET
ENABLED_STATE_SET
,
FOCUSED_STATE_SET
,
SELECTED_STATE_SET
protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET
PRESSED_STATE_SET
,
WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_SELECTED_STATE_SET
PRESSED_STATE_SET
,
SELECTED_STATE_SET
protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_STATE_SET
PRESSED_STATE_SET
,
FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET
PRESSED_STATE_SET
,
SELECTED_STATE_SET
,
FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_STATE_SET
PRESSED_STATE_SET
,
ENABLED_STATE_SET
protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET
PRESSED_STATE_SET
,
ENABLED_STATE_SET
,
SELECTED_STATE_SET
protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET
PRESSED_STATE_SET
,
ENABLED_STATE_SET
,
FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected Animation mCurrentAnimation
protected Object mTag
setTag(Object)
,
getTag()
public static final int LAYOUT_DIRECTION_UNDEFINED
public static final int LAYOUT_DIRECTION_LTR
setLayoutDirection(int)
.public static final int LAYOUT_DIRECTION_RTL
setLayoutDirection(int)
.public static final int LAYOUT_DIRECTION_INHERIT
setLayoutDirection(int)
.public static final int LAYOUT_DIRECTION_LOCALE
setLayoutDirection(int)
.public static final int TEXT_DIRECTION_INHERIT
ViewGroup
public static final int TEXT_DIRECTION_FIRST_STRONG
public static final int TEXT_DIRECTION_ANY_RTL
public static final int TEXT_DIRECTION_LTR
public static final int TEXT_DIRECTION_RTL
public static final int TEXT_DIRECTION_LOCALE
public static final int TEXT_DIRECTION_FIRST_STRONG_LTR
public static final int TEXT_DIRECTION_FIRST_STRONG_RTL
public static final int TEXT_ALIGNMENT_INHERIT
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_GRAVITY
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_TEXT_START
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_TEXT_END
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_CENTER
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_VIEW_START
setTextAlignment(int)
public static final int TEXT_ALIGNMENT_VIEW_END
setTextAlignment(int)
public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO
public static final int IMPORTANT_FOR_ACCESSIBILITY_YES
public static final int IMPORTANT_FOR_ACCESSIBILITY_NO
public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
public static final int ACCESSIBILITY_LIVE_REGION_NONE
Use with setAccessibilityLiveRegion(int)
.
public static final int ACCESSIBILITY_LIVE_REGION_POLITE
Use with setAccessibilityLiveRegion(int)
.
public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE
Use with setAccessibilityLiveRegion(int)
.
public static final int SCROLL_INDICATOR_TOP
public static final int SCROLL_INDICATOR_BOTTOM
public static final int SCROLL_INDICATOR_LEFT
public static final int SCROLL_INDICATOR_RIGHT
public static final int SCROLL_INDICATOR_START
Resolved according to the view's layout direction, see
getLayoutDirection()
for more information.
public static final int SCROLL_INDICATOR_END
Resolved according to the view's layout direction, see
getLayoutDirection()
for more information.
public static final int OVER_SCROLL_ALWAYS
public static final int OVER_SCROLL_IF_CONTENT_SCROLLS
public static final int OVER_SCROLL_NEVER
public static final int SYSTEM_UI_FLAG_VISIBLE
setSystemUiVisibility(int)
: View has
requested the system UI (status bar) to be visible (the default).setSystemUiVisibility(int)
,
Constant Field Valuespublic static final int SYSTEM_UI_FLAG_LOW_PROFILE
setSystemUiVisibility(int)
: View has requested the
system UI to enter an unobtrusive "low profile" mode.
This is for use in games, book readers, video players, or any other "immersive" application where the usual system chrome is deemed too distracting.
In low profile mode, the status bar and/or navigation icons may dim.
setSystemUiVisibility(int)
,
Constant Field Valuespublic static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION
setSystemUiVisibility(int)
: View has requested that the
system navigation be temporarily hidden.
This is an even less obtrusive state than that called for by
SYSTEM_UI_FLAG_LOW_PROFILE
; on devices that draw essential navigation controls
(Home, Back, and the like) on screen, SYSTEM_UI_FLAG_HIDE_NAVIGATION
will cause
those to disappear. This is useful (in conjunction with the
FLAG_FULLSCREEN
and
FLAG_LAYOUT_IN_SCREEN
window flags) for displaying content using every last pixel on the display.
There is a limitation: because navigation controls are so important, the least user
interaction will cause them to reappear immediately. When this happens, both
this flag and SYSTEM_UI_FLAG_FULLSCREEN
will be cleared automatically,
so that both elements reappear at the same time.
setSystemUiVisibility(int)
,
Constant Field Valuespublic static final int SYSTEM_UI_FLAG_FULLSCREEN
setSystemUiVisibility(int)
: View has requested to go
into the normal fullscreen mode so that its content can take over the screen
while still allowing the user to interact with the application.
This has the same visual effect as
WindowManager.LayoutParams.FLAG_FULLSCREEN
,
meaning that non-critical screen decorations (such as the status bar) will be
hidden while the user is in the View's window, focusing the experience on
that content. Unlike the window flag, if you are using ActionBar in
overlay mode with Window.FEATURE_ACTION_BAR_OVERLAY
, then enabling this flag will also
hide the action bar.
This approach to going fullscreen is best used over the window flag when
it is a transient state -- that is, the application does this at certain
points in its user interaction where it wants to allow the user to focus
on content, but not as a continuous state. For situations where the application
would like to simply stay full screen the entire time (such as a game that
wants to take over the screen), the
window flag
is usually a better approach. The state set here will be removed by the system
in various situations (such as the user moving to another application) like
the other system UI states.
When using this flag, the application should provide some easy facility for the user to go out of it. A common example would be in an e-book reader, where tapping on the screen brings back whatever screen and UI decorations that had been hidden while the user was immersed in reading the book.
setSystemUiVisibility(int)
,
Constant Field Valuespublic static final int SYSTEM_UI_FLAG_LAYOUT_STABLE
setSystemUiVisibility(int)
: When using other layout
flags, we would like a stable view of the content insets given to
fitSystemWindows(Rect)
. This means that the insets seen there
will always represent the worst case that the application can expect
as a continuous state. In the stock Android UI this is the space for
the system bar, nav bar, and status bar, but not more transient elements
such as an input method.
The stable layout your UI sees is based on the system UI modes you can
switch to. That is, if you specify SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
then you will get a stable layout for changes of the
SYSTEM_UI_FLAG_FULLSCREEN
mode; if you specify
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
and
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
, then you can transition
to SYSTEM_UI_FLAG_FULLSCREEN
and SYSTEM_UI_FLAG_HIDE_NAVIGATION
with a stable layout. (Note that you should avoid using
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
by itself.)
If you have set the window flag WindowManager.LayoutParams.FLAG_FULLSCREEN
to hide the status bar (instead of using SYSTEM_UI_FLAG_FULLSCREEN
),
then a hidden status bar will be considered a "stable" state for purposes
here. This allows your UI to continually hide the status bar, while still
using the system UI flags to hide the action bar while still retaining
a stable layout. Note that changing the window fullscreen flag will never
provide a stable layout for a clean transition.
If you are using ActionBar in
overlay mode with Window.FEATURE_ACTION_BAR_OVERLAY
, this flag will also impact the
insets it adds to those given to the application.
public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
setSystemUiVisibility(int)
: View would like its window
to be laid out as if it has requested
SYSTEM_UI_FLAG_HIDE_NAVIGATION
, even if it currently hasn't. This
allows it to avoid artifacts when switching in and out of that mode, at
the expense that some of its user interface may be covered by screen
decorations when they are shown. You can perform layout of your inner
UI elements to account for the navigation system UI through the
fitSystemWindows(Rect)
method.public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
setSystemUiVisibility(int)
: View would like its window
to be laid out as if it has requested
SYSTEM_UI_FLAG_FULLSCREEN
, even if it currently hasn't. This
allows it to avoid artifacts when switching in and out of that mode, at
the expense that some of its user interface may be covered by screen
decorations when they are shown. You can perform layout of your inner
UI elements to account for non-fullscreen system UI through the
fitSystemWindows(Rect)
method.public static final int SYSTEM_UI_FLAG_IMMERSIVE
setSystemUiVisibility(int)
: View would like to remain interactive when
hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION
. If this flag is
not set, SYSTEM_UI_FLAG_HIDE_NAVIGATION
will be force cleared by the system on any
user interaction.
Since this flag is a modifier for SYSTEM_UI_FLAG_HIDE_NAVIGATION
, it only
has an effect when used in combination with that flag.
public static final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY
setSystemUiVisibility(int)
: View would like to remain interactive when
hiding the status bar with SYSTEM_UI_FLAG_FULLSCREEN
and/or hiding the navigation
bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION
. Use this flag to create an immersive
experience while also hiding the system bars. If this flag is not set,
SYSTEM_UI_FLAG_HIDE_NAVIGATION
will be force cleared by the system on any user
interaction, and SYSTEM_UI_FLAG_FULLSCREEN
will be force-cleared by the system
if the user swipes from the top of the screen.
When system bars are hidden in immersive mode, they can be revealed temporarily with system gestures, such as swiping from the top of the screen. These transient system bars will overlay app’s content, may have some degree of transparency, and will automatically hide after a short timeout.
Since this flag is a modifier for SYSTEM_UI_FLAG_FULLSCREEN
and
SYSTEM_UI_FLAG_HIDE_NAVIGATION
, it only has an effect when used in combination
with one or both of those flags.
public static final int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
setSystemUiVisibility(int)
: Requests the status bar to draw in a mode that
is compatible with light status bar backgrounds.
For this to take effect, the window must request
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
but not
FLAG_TRANSLUCENT_STATUS
.
android.R.attr#windowLightStatusBar
,
Constant Field Valuespublic static final int STATUS_BAR_HIDDEN
SYSTEM_UI_FLAG_LOW_PROFILE
instead.public static final int STATUS_BAR_VISIBLE
SYSTEM_UI_FLAG_VISIBLE
instead.public static final int STATUS_BAR_DISABLE_EXPAND
public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS
public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS
public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER
public static final int STATUS_BAR_DISABLE_SYSTEM_INFO
public static final int STATUS_BAR_DISABLE_HOME
public static final int STATUS_BAR_DISABLE_BACK
public static final int STATUS_BAR_DISABLE_CLOCK
public static final int STATUS_BAR_DISABLE_RECENT
public static final int STATUS_BAR_DISABLE_SEARCH
public static final int STATUS_BAR_TRANSIENT
public static final int NAVIGATION_BAR_TRANSIENT
public static final int STATUS_BAR_UNHIDE
public static final int NAVIGATION_BAR_UNHIDE
public static final int STATUS_BAR_TRANSLUCENT
public static final int NAVIGATION_BAR_TRANSLUCENT
public static final int NAVIGATION_BAR_TRANSPARENT
public static final int STATUS_BAR_TRANSPARENT
public static final int SYSTEM_UI_TRANSPARENT
public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK
public static final int SYSTEM_UI_CLEARABLE_FLAGS
public static final int SYSTEM_UI_LAYOUT_FLAGS
public static final int FIND_VIEWS_WITH_TEXT
public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION
public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS
AccessibilityNodeProvider
. Such
a View is a root of virtual view hierarchy and may contain the searched
text. If this flag is set Views with providers are automatically
added and it is a responsibility of the client to call the APIs of
the provider to determine whether the virtual tree rooted at this View
contains the text, i.e. getting the list of AccessibilityNodeInfo
s
representing the virtual views with this text.public static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED
public static final int SCREEN_STATE_OFF
onScreenStateChanged(int)
,
Constant Field Valuespublic static final int SCREEN_STATE_ON
onScreenStateChanged(int)
,
Constant Field Valuespublic static final int SCROLL_AXIS_NONE
public static final int SCROLL_AXIS_HORIZONTAL
public static final int SCROLL_AXIS_VERTICAL
protected ViewParent mParent
getParent()
protected ViewGroup.LayoutParams mLayoutParams
ViewGroup
to determine how this view should be
laid out.
protected int mLeft
protected int mRight
protected int mTop
protected int mBottom
protected int mScrollX
protected int mScrollY
protected int mPaddingLeft
protected int mPaddingRight
protected int mPaddingTop
protected int mPaddingBottom
protected int mUserPaddingRight
protected int mUserPaddingBottom
protected int mUserPaddingLeft
protected Context mContext
public static final int DRAG_FLAG_GLOBAL
startDragAndDrop(ClipData, DragShadowBuilder, Object, int)
is called
with this flag set, all visible applications with targetSdkVersion >=
API 24
will be able to participate
in the drag operation and receive the dragged content.
If this is the only flag set, then the drag recipient will only have access to text data
and intents contained in the ClipData
object. Access to URIs contained in the
ClipData
is determined by other DRAG_FLAG_GLOBAL_* flags
public static final int DRAG_FLAG_GLOBAL_URI_READ
DRAG_FLAG_GLOBAL
, the drag recipient will be able to
request read access to the content URI(s) contained in the ClipData
object.android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
,
Constant Field Valuespublic static final int DRAG_FLAG_GLOBAL_URI_WRITE
DRAG_FLAG_GLOBAL
, the drag recipient will be able to
request write access to the content URI(s) contained in the ClipData
object.android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
,
Constant Field Valuespublic static final int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION
DRAG_FLAG_GLOBAL_URI_READ
and/or DRAG_FLAG_GLOBAL_URI_WRITE
, the URI permission grant can be persisted across device
reboots until explicitly revoked with
Context.revokeUriPermission
.android.content.Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
,
Constant Field Valuespublic static final int DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION
DRAG_FLAG_GLOBAL_URI_READ
and/or DRAG_FLAG_GLOBAL_URI_WRITE
, the URI permission grant applies to any URI that is a prefix
match against the original granted URI.android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
,
Constant Field Valuespublic static final int DRAG_FLAG_OPAQUE
startDragAndDrop(ClipData, DragShadowBuilder, Object, int)
is called
with this flag set, the drag shadow will be opaque, otherwise, it will be semitransparent.public static final int SCROLLBAR_POSITION_DEFAULT
public static final int SCROLLBAR_POSITION_LEFT
public static final int SCROLLBAR_POSITION_RIGHT
public static final int LAYER_TYPE_NONE
public static final int 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.)
public static final int 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.
public boolean mCachingFailed
protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier
public String[] mAttributes
public static final Property<View,Float> ALPHA
alpha
functionality handled by the
setAlpha(float)
and getAlpha()
methods.public static final Property<View,Float> TRANSLATION_X
translationX
functionality handled by the
setTranslationX(float)
and getTranslationX()
methods.public static final Property<View,Float> TRANSLATION_Y
translationY
functionality handled by the
setTranslationY(float)
and getTranslationY()
methods.public static final Property<View,Float> TRANSLATION_Z
translationZ
functionality handled by the
setTranslationZ(float)
and getTranslationZ()
methods.public static final Property<View,Float> ROTATION
rotation
functionality handled by the
setRotation(float)
and getRotation()
methods.public static final Property<View,Float> ROTATION_X
rotationX
functionality handled by the
setRotationX(float)
and getRotationX()
methods.public static final Property<View,Float> ROTATION_Y
rotationY
functionality handled by the
setRotationY(float)
and getRotationY()
methods.public static final Property<View,Float> SCALE_X
scaleX
functionality handled by the
setScaleX(float)
and getScaleX()
methods.public static final Property<View,Float> SCALE_Y
scaleY
functionality handled by the
setScaleY(float)
and getScaleY()
methods.public View(Context context)
context
- The Context the view is running in, through which it can
access the current theme, resources, etc.public View(Context context, AttributeSet attrs)
The method onFinishInflate() will be called after all children have been added.
context
- The Context the view is running in, through which it can
access the current theme, resources, etc.attrs
- The attributes of the XML tag that is inflating the view.View(Context, AttributeSet, int)
public View(Context context, AttributeSet attrs, int defStyleAttr)
R.attr.buttonStyle
for defStyleAttr; this
allows the theme's button style to modify all of the base view attributes
(in particular its background) as well as the Button class's attributes.context
- The Context the view is running in, through which it can
access the current theme, resources, etc.attrs
- The attributes of the XML tag that is inflating the view.defStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.View(Context, AttributeSet)
public View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
When determining the final value of a particular attribute, there are four inputs that come into play:
Each of these inputs is considered in-order, with the first listed taking
precedence over the following ones. In other words, if in the
AttributeSet you have supplied <Button * textColor="#ff000000">
, then the button's text will always be black, regardless of
what is specified in any of the styles.
context
- The Context the view is running in, through which it can
access the current theme, resources, etc.attrs
- The attributes of the XML tag that is inflating the view.defStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.defStyleRes
- A resource identifier of a style resource that
supplies default values for the view, used only if
defStyleAttr is 0 or can not be found in the theme. Can be 0
to not look for defaults.View(Context, AttributeSet, int)
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
protected void initializeFadingEdge(TypedArray a)
Initializes the fading edges from a given set of styled attributes. This method should be called by subclasses that need fading edges and when an instance of these subclasses is created programmatically rather than being inflated from XML. This method is automatically called when the XML is inflated.
a
- the styled attributes set to initialize the fading edges fromprotected void initializeFadingEdgeInternal(TypedArray a)
Initializes the fading edges from a given set of styled attributes. This method should be called by subclasses that need fading edges and when an instance of these subclasses is created programmatically rather than being inflated from XML. This method is automatically called when the XML is inflated.
a
- the styled attributes set to initialize the fading edges frompublic int getVerticalFadingEdgeLength()
public void setFadingEdgeLength(int length)
setVerticalFadingEdgeEnabled(boolean)
or
setHorizontalFadingEdgeEnabled(boolean)
to enable the fading edge
for the vertical or horizontal fading edges.length
- The size in pixels of the faded edge used to indicate that more
content in this view is visible.public int getHorizontalFadingEdgeLength()
public int getVerticalScrollbarWidth()
protected int getHorizontalScrollbarHeight()
protected void initializeScrollbars(TypedArray a)
Initializes the scrollbars from a given set of styled attributes. This method should be called by subclasses that need scrollbars and when an instance of these subclasses is created programmatically rather than being inflated from XML. This method is automatically called when the XML is inflated.
a
- the styled attributes set to initialize the scrollbars fromprotected void initializeScrollbarsInternal(TypedArray a)
Initializes the scrollbars from a given set of styled attributes. This method should be called by subclasses that need scrollbars and when an instance of these subclasses is created programmatically rather than being inflated from XML. This method is automatically called when the XML is inflated.
a
- the styled attributes set to initialize the scrollbars frompublic void setVerticalScrollbarPosition(int position)
SCROLLBAR_POSITION_DEFAULT
, SCROLLBAR_POSITION_LEFT
or
SCROLLBAR_POSITION_RIGHT
.position
- Where the vertical scroll bar should be positioned.public int getVerticalScrollbarPosition()
setVerticalScrollbarPosition(int)
public void setScrollIndicators(int indicators)
See setScrollIndicators(int, int)
for usage information.
indicators
- a bitmask of indicators that should be enabled, or
0
to disable all indicatorssetScrollIndicators(int, int)
,
getScrollIndicators()
public void setScrollIndicators(int indicators, int mask)
setScrollIndicators(int)
.
When a scroll indicator is enabled, it will be displayed if the view can scroll in the direction of the indicator.
Multiple indicator types may be enabled or disabled by passing the logical OR of the desired types. If multiple types are specified, they will all be set to the same enabled state.
For example, to enable the top scroll indicatorExample: {@code setScrollIndicators
indicators
- the indicator direction, or the logical OR of multiple
indicator directions. One or more of:
setScrollIndicators(int)
,
getScrollIndicators()
public int getScrollIndicators()
For example, if the top and left scroll indicators are enabled and all
other indicators are disabled, the return value will be
View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_LEFT
.
To check whether the bottom scroll indicator is enabled, use the value
of (getScrollIndicators() & View.SCROLL_INDICATOR_BOTTOM) != 0
.
public void setOnScrollChangeListener(View.OnScrollChangeListener l)
Note: Some views handle scrolling independently from View and may
have their own separate listeners for scroll-type events. For example,
ListView
allows clients to register an
AbsListView.OnScrollListener
to listen for changes in list scroll position.
l
- The listener to notify when the scroll X or Y position changes.getScrollX()
,
getScrollY()
public void setOnFocusChangeListener(View.OnFocusChangeListener l)
l
- The callback that will run.public void addOnLayoutChangeListener(View.OnLayoutChangeListener listener)
listener
- The listener that will be called when layout bounds change.public void removeOnLayoutChangeListener(View.OnLayoutChangeListener listener)
listener
- The listener for layout bounds change.public void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)
removeOnAttachStateChangeListener(OnAttachStateChangeListener)
.listener
- Listener to attachremoveOnAttachStateChangeListener(OnAttachStateChangeListener)
public void removeOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)
listener
- Listener to removeaddOnAttachStateChangeListener(OnAttachStateChangeListener)
public View.OnFocusChangeListener getOnFocusChangeListener()
public void setOnClickListener(View.OnClickListener l)
l
- The callback that will runsetClickable(boolean)
public boolean hasOnClickListeners()
public void setOnLongClickListener(View.OnLongClickListener l)
l
- The callback that will runsetLongClickable(boolean)
public void setOnContextClickListener(View.OnContextClickListener l)
l
- The callback that will runsetContextClickable(boolean)
public void setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)
l
- The callback that will runpublic void addFrameMetricsListener(Window window, Window.OnFrameMetricsAvailableListener listener, Handler handler)
public void removeFrameMetricsListener(Window.OnFrameMetricsAvailableListener listener)
public boolean performClick()
public boolean callOnClick()
performClick()
,
this only calls the listener, and does not do any associated clicking
actions like reporting an accessibility event.public boolean performLongClick()
true
if one of the above receivers consumed the event,
false
otherwisepublic boolean performLongClick(float x, float y)
public boolean performContextClick(float x, float y)
x
- the x coordinate of the context clicky
- the y coordinate of the context clickpublic boolean performContextClick()
protected boolean performButtonActionOnTouchDown(MotionEvent event)
event
- The event.public boolean showContextMenu()
true
if the context menu was shown, false
otherwiseshowContextMenu(float, float)
public boolean showContextMenu(float x, float y)
x
- the X coordinate in pixels relative to the view to which the
menu should be anchored, or Float.NaN
to disable anchoringy
- the Y coordinate in pixels relative to the view to which the
menu should be anchored, or Float.NaN
to disable anchoringtrue
if the context menu was shown, false
otherwisepublic ActionMode startActionMode(ActionMode.Callback callback)
ActionMode.TYPE_PRIMARY
.callback
- Callback that will control the lifecycle of the action modeActionMode
,
startActionMode(android.view.ActionMode.Callback, int)
public ActionMode startActionMode(ActionMode.Callback callback, int type)
callback
- Callback that will control the lifecycle of the action modetype
- One of ActionMode.TYPE_PRIMARY
or ActionMode.TYPE_FLOATING
.ActionMode
public void startActivityForResult(Intent intent, int requestCode)
Context.startActivityForResult(String, Intent, int, Bundle)
for the View's
Context, creating a unique View identifier to retrieve the result.intent
- The Intent to be started.requestCode
- The request code to use.public boolean dispatchActivityResult(String who, int requestCode, int resultCode, Intent data)
who
- The identifier for the targeted View to receive the result.requestCode
- The integer request code originally supplied to
startActivityForResult(), allowing you to identify who this
result came from.resultCode
- The integer result code returned by the child activity
through its setResult().data
- An Intent, which can return result data to the caller
(various data can be attached to Intent "extras").true
if the activity result was dispatched.public void onActivityResult(int requestCode, int resultCode, Intent data)
startActivityForResult(Intent, int)
.requestCode
- The integer request code originally supplied to
startActivityForResult(), allowing you to identify who this
result came from.resultCode
- The integer result code returned by the child activity
through its setResult().data
- An Intent, which can return result data to the caller
(various data can be attached to Intent "extras").public void setOnKeyListener(View.OnKeyListener l)
l
- the key listener to attach to this viewpublic void setOnTouchListener(View.OnTouchListener l)
l
- the touch listener to attach to this viewpublic void setOnGenericMotionListener(View.OnGenericMotionListener l)
l
- the generic motion listener to attach to this viewpublic void setOnHoverListener(View.OnHoverListener l)
l
- the hover listener to attach to this viewpublic void setOnDragListener(View.OnDragListener l)
View.OnDragListener
. To send a drag event to a
View, the system calls the
View.OnDragListener.onDrag(View,DragEvent)
method.l
- An implementation of View.OnDragListener
.public final void setRevealOnFocusHint(boolean revealOnFocus)
When set to true, this is a signal to ancestor views in the hierarchy that this view would prefer to be brought fully into view when it gains focus. For example, a text field that a user is meant to type into. Other views such as scrolling containers may prefer to opt-out of this behavior.
The default value for views is true, though subclasses may change this based on their preferred behavior.
revealOnFocus
- true to request reveal on focus in ancestors, false otherwisegetRevealOnFocusHint()
public final boolean getRevealOnFocusHint()
When this method returns true for a child view requesting focus, ancestor
views responding to a focus change in ViewParent.requestChildFocus(View, View)
should make a best effort to make the newly focused child fully visible to the user.
When it returns false, ancestor views should preferably not disrupt scroll positioning or
other properties affecting visibility to the user as part of the focus change.
setRevealOnFocusHint(boolean)
public void getHotspotBounds(Rect outRect)
outRect
with the hotspot bounds. By default,
the hotspot bounds are identical to the screen bounds.outRect
- rect to populate with hotspot boundspublic boolean requestRectangleOnScreen(Rect rectangle)
A View should call this if it maintains some notion of which part of its content is interesting. For example, a text editing view should call this when its cursor moves.
The Rectangle passed into this method should be in the View's content coordinate space. It should not be affected by which part of the View is currently visible or its scroll position.
rectangle
- The rectangle in the View's content coordinate spacepublic boolean requestRectangleOnScreen(Rect rectangle, boolean immediate)
A View should call this if it maintains some notion of which part of its content is interesting. For example, a text editing view should call this when its cursor moves.
The Rectangle passed into this method should be in the View's content coordinate space. It should not be affected by which part of the View is currently visible or its scroll position.
When immediate
is set to true, scrolling will not be
animated.
rectangle
- The rectangle in the View's content coordinate spaceimmediate
- True to forbid animated scrolling, false otherwisepublic void clearFocus()
onFocusChanged(boolean, int, android.graphics.Rect)
is called.
Note: When a View clears focus the framework is trying to give focus to the first focusable View from the top. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.
public boolean hasFocus()
public boolean hasFocusable()
hasFocusable()
returns true. A "reachable hasFocusable()"
is a View whose parents do not block descendants focus.
Only VISIBLE
views are considered focusable.ViewGroup.FOCUS_BLOCK_DESCENDANTS
,
ViewGroup.getTouchscreenBlocksFocus()
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
gainFocus
- True if the View has focus; false otherwise.direction
- The direction focus has moved when requestFocus()
is called to give this view focus. Values are
FOCUS_UP
, FOCUS_DOWN
, FOCUS_LEFT
,
FOCUS_RIGHT
, FOCUS_FORWARD
, or FOCUS_BACKWARD
.
It may not always apply, in which case use the default.previouslyFocusedRect
- The rectangle, in this view's coordinate
system, of the previously focused view. If applicable, this will be
passed in as finer grained information about where the focus is coming
from (in addition to direction). Will be null
otherwise.public void sendAccessibilityEvent(int eventType)
onInitializeAccessibilityEvent(AccessibilityEvent)
first
to populate information about the event source (this View), then calls
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
to
populate the text content of the event source including its descendants,
and last calls
ViewParent.requestSendAccessibilityEvent(View, AccessibilityEvent)
on its parent to request sending of the event to interested parties.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.sendAccessibilityEvent(View, int)
is
responsible for handling this call.
sendAccessibilityEvent
in interface AccessibilityEventSource
eventType
- The type of the event to send, as defined by several types from
AccessibilityEvent
, such as
AccessibilityEvent.TYPE_VIEW_CLICKED
or
AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
.onInitializeAccessibilityEvent(AccessibilityEvent)
,
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
,
ViewParent.requestSendAccessibilityEvent(View, AccessibilityEvent)
,
View.AccessibilityDelegate
public void announceForAccessibility(CharSequence text)
AccessibilityEvent.TYPE_ANNOUNCEMENT
AccessibilityEvent
to make an announcement which is related to some
sort of a context change for which none of the events representing UI transitions
is a good fit. For example, announcing a new page in a book. If accessibility
is not enabled this method does nothing.text
- The announcement text.public void sendAccessibilityEventInternal(int eventType)
public void sendAccessibilityEventUnchecked(AccessibilityEvent event)
sendAccessibilityEvent(int)
but
takes as an argument an empty AccessibilityEvent
and does not
perform a check whether accessibility is enabled.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.sendAccessibilityEventUnchecked(View, AccessibilityEvent)
is responsible for handling this call.
sendAccessibilityEventUnchecked
in interface AccessibilityEventSource
event
- The event to send.sendAccessibilityEvent(int)
public void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event)
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
AccessibilityEvent
to the View
first and then
to its children for adding their text content to the event. Note that the
event text is populated in a separate dispatch path since we add to the
event not only the text of the source but also the text of all its descendants.
A typical implementation will call
onPopulateAccessibilityEvent(AccessibilityEvent)
on the this view
and then call the dispatchPopulateAccessibilityEvent(AccessibilityEvent)
on each child. Override this method if custom population of the event text
content is required.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Accessibility events of certain types are not dispatched for
populating the event text via this method. For details refer to AccessibilityEvent
.
event
- The event.public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event)
public void onPopulateAccessibilityEvent(AccessibilityEvent event)
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
giving a chance to this View to populate the accessibility event with its
text content. While this method is free to modify event
attributes other than text content, doing so should normally be performed in
onInitializeAccessibilityEvent(AccessibilityEvent)
.
Example: Adding formatted date string to an accessibility event in addition to the text added by the super implementation:
public void onPopulateAccessibilityEvent(AccessibilityEvent event) { super.onPopulateAccessibilityEvent(event); final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; String selectedDateUtterance = DateUtils.formatDateTime(mContext, mCurrentDate.getTimeInMillis(), flags); event.getText().add(selectedDateUtterance); }
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onPopulateAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
event
- The accessibility event which to populate.sendAccessibilityEvent(int)
,
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
public void onPopulateAccessibilityEventInternal(AccessibilityEvent event)
public void onInitializeAccessibilityEvent(AccessibilityEvent event)
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:
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setPassword(true); }
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
event
- The event to initialize.sendAccessibilityEvent(int)
,
dispatchPopulateAccessibilityEvent(AccessibilityEvent)
public void onInitializeAccessibilityEventInternal(AccessibilityEvent event)
public AccessibilityNodeInfo createAccessibilityNodeInfo()
AccessibilityNodeInfo
representing this view from the
point of view of an AccessibilityService
.
This method is responsible for obtaining an accessibility node info from a
pool of reusable instances and calling
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)
on this view to
initialize the former.
Note: The client is responsible for recycling the obtained instance by calling
AccessibilityNodeInfo.recycle()
to minimize object creation.
AccessibilityNodeInfo
.AccessibilityNodeInfo
public AccessibilityNodeInfo createAccessibilityNodeInfoInternal()
createAccessibilityNodeInfo()
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
AccessibilityNodeInfo
with information about this view.
The base implementation sets:
AccessibilityNodeInfo.setParent(View)
,AccessibilityNodeInfo.setBoundsInParent(Rect)
,AccessibilityNodeInfo.setBoundsInScreen(Rect)
,AccessibilityNodeInfo.setPackageName(CharSequence)
,AccessibilityNodeInfo.setClassName(CharSequence)
,AccessibilityNodeInfo.setContentDescription(CharSequence)
,AccessibilityNodeInfo.setEnabled(boolean)
,AccessibilityNodeInfo.setClickable(boolean)
,AccessibilityNodeInfo.setFocusable(boolean)
,AccessibilityNodeInfo.setFocused(boolean)
,AccessibilityNodeInfo.setLongClickable(boolean)
,AccessibilityNodeInfo.setSelected(boolean)
,AccessibilityNodeInfo.setContextClickable(boolean)
Subclasses should override this method, call the super implementation, and set additional attributes.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)
is responsible for handling this call.
info
- The instance to initialize.public void getBoundsOnScreen(Rect outRect)
outRect
- The output locationpublic void getBoundsOnScreen(Rect outRect, boolean clipToParent)
outRect
- The output locationclipToParent
- Whether to clip child bounds to the parent ones.public CharSequence getAccessibilityClassName()
AccessibilityNodeInfo.setClassName
.public void onProvideStructure(ViewStructure structure)
Activity.onProvideAssistData
.structure
- Fill in with structured view data. The default implementation
fills in all data that can be inferred from the view itself.public void onProvideVirtualStructure(ViewStructure structure)
Activity.onProvideAssistData
to
generate additional virtual structure under this view. The defaullt implementation
uses getAccessibilityNodeProvider()
to try to generate this from the
view's virtual accessibility nodes, if any. You can override this for a more
optimal implementation providing this data.public void dispatchProvideStructure(ViewStructure structure)
ViewStructure
down the hierarchy. The default
implementation calls onProvideStructure(android.view.ViewStructure)
and
onProvideVirtualStructure(android.view.ViewStructure)
.public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info)
protected boolean isVisibleToUser()
protected boolean isVisibleToUser(Rect boundInView)
boundInView
- the portion of the view to test; coordinates should be relative; may be
null
, and the entire view will be tested in this case.
When true
is returned by the function, the actual visible
region will be stored in this parameter; that is, if boundInView is fully
contained within the view, no modification will be made, otherwise regions
outside of the visible area of the view will be clipped.public View.AccessibilityDelegate getAccessibilityDelegate()
View.AccessibilityDelegate
.public void setAccessibilityDelegate(View.AccessibilityDelegate delegate)
View.AccessibilityDelegate
.
Note: On platform versions prior to
API 23
, delegate methods on
views in the android.widget.*
package are called before
host methods. This prevents certain properties such as class name from
being modified by overriding
View.AccessibilityDelegate.onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)
,
as any changes will be overwritten by the host class.
Starting in API 23
, delegate
methods are called after host methods, which all properties to be
modified without being overwritten by the host class.
delegate
- the object to which accessibility method calls should be
delegatedView.AccessibilityDelegate
public AccessibilityNodeProvider getAccessibilityNodeProvider()
AccessibilityService
s
that explore the window content.
If this method returns an instance, this instance is responsible for managing
AccessibilityNodeInfo
s 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.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.getAccessibilityNodeProvider(View)
is responsible for handling this call.
AccessibilityNodeProvider
public int getAccessibilityViewId()
View
is not attached to any window, -1 is returned.public int getAccessibilityWindowId()
public CharSequence getContentDescription()
View
's content description.
Note: Do not override this method, as it will have no
effect on the content description presented to accessibility services.
You must call setContentDescription(CharSequence)
to modify the
content description.
setContentDescription(CharSequence)
public void setContentDescription(CharSequence contentDescription)
View
's content description.
A content description briefly describes the view and is primarily used
for accessibility support to determine how a view should be presented to
the user. In the case of a view with no textual representation, such as
ImageButton
, a useful content description
explains what the view does. For example, an image button with a phone
icon that is used to place a call may use "Call" as its content
description. An image of a floppy disk that is used to save a file may
use "Save".
contentDescription
- The content description.getContentDescription()
public void setAccessibilityTraversalBefore(int beforeId)
Views that do not have specified before/after relationships are traversed in order determined by the screen-reader.
Setting that this view is before a view that is not important for accessibility or if this view is not important for accessibility will have no effect as the screen-reader is not aware of unimportant views.
beforeId
- The id of a view this one precedes in accessibility traversal.setImportantForAccessibility(int)
public int getAccessibilityTraversalBefore()
NO_ID
.setAccessibilityTraversalBefore(int)
public void setAccessibilityTraversalAfter(int afterId)
Views that do not have specified before/after relationships are traversed in order determined by the screen-reader.
Setting that this view is after a view that is not important for accessibility or if this view is not important for accessibility will have no effect as the screen-reader is not aware of unimportant views.
afterId
- The id of a view this one succedees in accessibility traversal.setImportantForAccessibility(int)
public int getAccessibilityTraversalAfter()
NO_ID
.setAccessibilityTraversalAfter(int)
public int getLabelFor()
public void setLabelFor(@IdRes int id)
id
- The labeled view id.protected void onFocusLost()
public boolean isFocused()
public View findFocus()
public boolean isScrollContainer()
public void setScrollContainer(boolean isScrollContainer)
public int getDrawingCacheQuality()
public void setDrawingCacheQuality(int quality)
quality
- One of DRAWING_CACHE_QUALITY_AUTO
,
DRAWING_CACHE_QUALITY_LOW
, or DRAWING_CACHE_QUALITY_HIGH
getDrawingCacheQuality()
,
setDrawingCacheEnabled(boolean)
,
isDrawingCacheEnabled()
public boolean getKeepScreenOn()
KEEP_SCREEN_ON
.KEEP_SCREEN_ON
is set.setKeepScreenOn(boolean)
public void setKeepScreenOn(boolean keepScreenOn)
KEEP_SCREEN_ON
.keepScreenOn
- Supply true to set KEEP_SCREEN_ON
.getKeepScreenOn()
public int getNextFocusLeftId()
FOCUS_LEFT
.NO_ID
if the framework should decide automatically.public void setNextFocusLeftId(int nextFocusLeftId)
FOCUS_LEFT
.nextFocusLeftId
- The next focus ID, or NO_ID
if the framework should
decide automatically.public int getNextFocusRightId()
FOCUS_RIGHT
.NO_ID
if the framework should decide automatically.public void setNextFocusRightId(int nextFocusRightId)
FOCUS_RIGHT
.nextFocusRightId
- The next focus ID, or NO_ID
if the framework should
decide automatically.public int getNextFocusUpId()
FOCUS_UP
.NO_ID
if the framework should decide automatically.public void setNextFocusUpId(int nextFocusUpId)
FOCUS_UP
.nextFocusUpId
- The next focus ID, or NO_ID
if the framework should
decide automatically.public int getNextFocusDownId()
FOCUS_DOWN
.NO_ID
if the framework should decide automatically.public void setNextFocusDownId(int nextFocusDownId)
FOCUS_DOWN
.nextFocusDownId
- The next focus ID, or NO_ID
if the framework should
decide automatically.public int getNextFocusForwardId()
FOCUS_FORWARD
.NO_ID
if the framework should decide automatically.public void setNextFocusForwardId(int nextFocusForwardId)
FOCUS_FORWARD
.nextFocusForwardId
- The next focus ID, or NO_ID
if the framework should
decide automatically.public boolean isShown()
VISIBLE
protected boolean fitSystemWindows(Rect insets)
dispatchApplyWindowInsets(WindowInsets)
to apply
insets to views. Views should override onApplyWindowInsets(WindowInsets)
or use
setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener)
to implement handling their own insets.You do not normally need to deal with this function, since the default
window decoration given to applications takes care of applying it to the
content of the window. If you use SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
this will not be the case,
and your content can be placed under those system elements. You can then
use this method within your view hierarchy if you have parts of your UI
which you would like to ensure are not being covered.
The default implementation of this method simply applies the content
insets to the view's padding, consuming that content (modifying the
insets to be 0), and returning true. This behavior is off by default, but can
be enabled through setFitsSystemWindows(boolean)
.
This function's traversal down the hierarchy is depth-first. The same content insets object is propagated down the hierarchy, so any changes made to it will be seen by all following views (including potentially ones above in the hierarchy since this is a depth-first traversal). The first view that returns true will abort the entire traversal.
The default implementation works well for a situation where it is used with a container that covers the entire window, allowing it to apply the appropriate insets to its content on all edges. If you need a more complicated layout (such as two different views fitting system windows, one on the top of the window, and one on the bottom), you can override the method and handle the insets however you would like. Note that the insets provided by the framework are always relative to the far edges of the window, not accounting for the location of the called view within that window. (In fact when this method is called you do not yet know where the layout will place the view, as it is done before layout happens.)
Note: unlike many View methods, there is no dispatch phase to this call. If you are overriding it in a ViewGroup and want to allow the call to continue to your children, you must be sure to call the super implementation.
Here is a sample layout that makes use of fitting system windows
to have controls for a video view placed inside of the window decorations
that it hides and shows. This can be used with code like the second
sample (video player) shown in setSystemUiVisibility(int)
.
insets
- Current content insets of the window. Prior to
Build.VERSION_CODES.JELLY_BEAN
you must not modify
the insets or else you and Android will be unhappy.true
if this view applied the insets and it should not
continue propagating further down the hierarchy, false
otherwise.getFitsSystemWindows()
,
setFitsSystemWindows(boolean)
,
setSystemUiVisibility(int)
public WindowInsets onApplyWindowInsets(WindowInsets insets)
WindowInsets
according to its internal policy.
This method should be overridden by views that wish to apply a policy different from or
in addition to the default behavior. Clients that wish to force a view subtree
to apply insets should call dispatchApplyWindowInsets(WindowInsets)
.
Clients may supply an View.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.
Implementations of this method should either return the insets parameter unchanged
or a new WindowInsets
cloned from the supplied insets with any insets consumed
that this view applied itself. This allows new inset types added in future platform
versions to pass through existing implementations unchanged without being erroneously
consumed.
By default if a view's fitsSystemWindows
property is set then the view will consume the system window insets and apply them
as padding for the view.
insets
- Insets to applypublic void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
View.OnApplyWindowInsetsListener
to take over the policy for applying
window insets to this view. The listener's
onApplyWindowInsets
method will be called instead of the view's
onApplyWindowInsets
method.listener
- Listener to setonApplyWindowInsets(WindowInsets)
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets)
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.
Clients wishing to provide custom behavior should override the
onApplyWindowInsets(WindowInsets)
method or alternatively provide a
View.OnApplyWindowInsetsListener
via the
setOnApplyWindowInsetsListener
method.
This method replaces the older fitSystemWindows
method.
insets
- Insets to applypublic void getLocationInSurface(int[] location)
Computes the coordinates of this view in its surface. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.
location
- an array of two integers in which to hold the coordinatespublic WindowInsets getRootWindowInsets()
protected boolean computeFitSystemWindows(Rect inoutInsets, Rect outLocalInsets)
public WindowInsets computeSystemWindowInsets(WindowInsets in, Rect outLocalInsets)
in
- Insets currently being processed by this View, likely received as a parameter
to onApplyWindowInsets(WindowInsets)
.outLocalInsets
- A Rect that will receive the insets that should be consumed
by this viewpublic void setFitsSystemWindows(boolean fitSystemWindows)
fitSystemWindows(Rect)
will be
executed. See that method for more details.
Note that if you are providing your own implementation of
fitSystemWindows(Rect)
, then there is no need to set this
flag to true -- your implementation will be overriding the default
implementation that checks this flag.
fitSystemWindows
- If true, then the default implementation of
fitSystemWindows(Rect)
will be executed.getFitsSystemWindows()
,
fitSystemWindows(Rect)
,
setSystemUiVisibility(int)
public boolean getFitsSystemWindows()
setFitsSystemWindows(boolean)
. If this method
returns true
, the default implementation of fitSystemWindows(Rect)
will be executed.true
if the default implementation of
fitSystemWindows(Rect)
will be executed.setFitsSystemWindows(boolean)
,
fitSystemWindows(Rect)
,
setSystemUiVisibility(int)
public boolean fitsSystemWindows()
public void requestFitSystemWindows()
requestApplyInsets()
for newer platform versions.fitSystemWindows(Rect)
be performed.public void requestApplyInsets()
onApplyWindowInsets(WindowInsets)
be performed.public void makeOptionalFitsSystemWindows()
public void getOutsets(Rect outOutsetRect)
public int getVisibility()
public void setVisibility(int visibility)
public boolean isEnabled()
public void setEnabled(boolean enabled)
enabled
- True if this view is enabled, false otherwise.public void setFocusable(boolean focusable)
focusable
- If true, this view can receive the focus.setFocusableInTouchMode(boolean)
public void setFocusableInTouchMode(boolean focusableInTouchMode)
focusableInTouchMode
- If true, this view can receive the focus while
in touch mode.setFocusable(boolean)
public void setSoundEffectsEnabled(boolean soundEffectsEnabled)
You may wish to disable sound effects for a view if you already play sounds, for instance, a dial key that plays dtmf tones.
soundEffectsEnabled
- whether sound effects are enabled for this view.isSoundEffectsEnabled()
,
playSoundEffect(int)
public boolean isSoundEffectsEnabled()
setSoundEffectsEnabled(boolean)
,
playSoundEffect(int)
public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
You may wish to disable haptic feedback if your view already controls its own haptic feedback.
hapticFeedbackEnabled
- whether haptic feedback enabled for this view.isHapticFeedbackEnabled()
,
performHapticFeedback(int)
public boolean isHapticFeedbackEnabled()
setHapticFeedbackEnabled(boolean)
,
performHapticFeedback(int)
public int getRawLayoutDirection()
LAYOUT_DIRECTION_LTR
,
LAYOUT_DIRECTION_RTL
,
LAYOUT_DIRECTION_INHERIT
or
LAYOUT_DIRECTION_LOCALE
.public void setLayoutDirection(int layoutDirection)
layoutDirection
- the layout direction to set. Should be one of:
LAYOUT_DIRECTION_LTR
,
LAYOUT_DIRECTION_RTL
,
LAYOUT_DIRECTION_INHERIT
,
LAYOUT_DIRECTION_LOCALE
.
Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution
proceeds up the parent chain of the view to get the value. If there is no parent, then it
will return the default LAYOUT_DIRECTION_LTR
.public int getLayoutDirection()
LAYOUT_DIRECTION_RTL
if the layout direction is RTL or returns
LAYOUT_DIRECTION_LTR
if the layout direction is not RTL.
For compatibility, this will return LAYOUT_DIRECTION_LTR
if API version
is lower than Build.VERSION_CODES.JELLY_BEAN_MR1
.public boolean isLayoutRtl()
public boolean hasTransientState()
A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.
public void setHasTransientState(boolean hasTransientState)
A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.
hasTransientState
- true if this view has transient statepublic boolean isAttachedToWindow()
public boolean isLaidOut()
public void setWillNotDraw(boolean willNotDraw)
onDraw(android.graphics.Canvas)
you should clear this flag.willNotDraw
- whether or not this View draw on its ownpublic boolean willNotDraw()
public void setWillNotCacheDrawing(boolean willNotCacheDrawing)
willNotCacheDrawing
- true if this view does not cache its
drawing, false otherwisepublic boolean willNotCacheDrawing()
public boolean isClickable()
setClickable(boolean)
public void setClickable(boolean clickable)
clickable
- true to make the view clickable, false otherwiseisClickable()
public boolean isLongClickable()
setLongClickable(boolean)
public void setLongClickable(boolean longClickable)
longClickable
- true to make the view long clickable, false otherwiseisLongClickable()
public boolean isContextClickable()
setContextClickable(boolean)
public void setContextClickable(boolean contextClickable)
contextClickable
- true to make the view react to a context click, false otherwiseisContextClickable()
public void setPressed(boolean pressed)
pressed
- Pass true to set the View's internal state to "pressed", or false to reverts
the View's internal state from a previously set "pressed" state.isClickable()
,
setClickable(boolean)
protected void dispatchSetPressed(boolean pressed)
pressed
- The new pressed statesetPressed(boolean)
public boolean isPressed()
setPressed(boolean)
is explicitly called, only clickable views can enter
the pressed state.setPressed(boolean)
,
isClickable()
,
setClickable(boolean)
public boolean isAssistBlocked()
setAssistBlocked(boolean)
public void setAssistBlocked(boolean enabled)
enabled
- Set to true to disable assist data collection, or false
(the default) to allow it.isAssistBlocked()
,
onProvideStructure(android.view.ViewStructure)
,
onProvideVirtualStructure(android.view.ViewStructure)
public boolean isSaveEnabled()
onSaveInstanceState()
method will be called).setSaveEnabled(boolean)
public void setSaveEnabled(boolean enabled)
onSaveInstanceState()
method
will be called). Note that even if freezing is enabled, the
view still must have an id assigned to it (via setId(int)
)
for its state to be saved. This flag can only disable the
saving of this view; any child views may still have their state saved.enabled
- Set to false to disable state saving, or true
(the default) to allow it.isSaveEnabled()
,
setId(int)
,
onSaveInstanceState()
public boolean getFilterTouchesWhenObscured()
View
security documentation for more details.setFilterTouchesWhenObscured(boolean)
public void setFilterTouchesWhenObscured(boolean enabled)
View
security documentation for more details.enabled
- True if touch filtering should be enabled.getFilterTouchesWhenObscured()
public boolean isSaveFromParentEnabled()
saveHierarchyState(SparseArray)
is called directly on this view.setSaveFromParentEnabled(boolean)
public void setSaveFromParentEnabled(boolean enabled)
saveHierarchyState(SparseArray)
is called directly on this view.enabled
- Set to false to disable state saving, or true
(the default) to allow it.isSaveFromParentEnabled()
,
setId(int)
,
onSaveInstanceState()
public final boolean isFocusable()
public final boolean isFocusableInTouchMode()
public View focusSearch(int direction)
direction
- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHTpublic boolean dispatchUnhandledMove(View focused, int direction)
focused
- The currently focused view.direction
- The direction focus wants to move. One of FOCUS_UP,
FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT.public ArrayList<View> getFocusables(int direction)
direction
- The direction of the focuspublic void addFocusables(ArrayList<View> views, int direction)
views
- Focusable views found so fardirection
- The direction of the focuspublic void addFocusables(ArrayList<View> views, int direction, int focusableMode)
views
- Focusable views found so far or null if all we are interested is
the number of focusables.direction
- The direction of the focus.focusableMode
- The type of focusables to be added.FOCUSABLES_ALL
,
FOCUSABLES_TOUCH_MODE
public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags)
FIND_VIEWS_WITH_TEXT
and
FIND_VIEWS_WITH_CONTENT_DESCRIPTION
flags.outViews
- The output list of matching Views.searched
- The text to match against.FIND_VIEWS_WITH_TEXT
,
FIND_VIEWS_WITH_CONTENT_DESCRIPTION
,
setContentDescription(CharSequence)
public ArrayList<View> getTouchables()
public void addTouchables(ArrayList<View> views)
views
- Touchable views found so farpublic boolean isAccessibilityFocused()
public boolean requestAccessibilityFocus()
AccessibilityManager.isEnabled()
returns false or the view is no visible or the view already has accessibility
focus.
See also focusSearch(int)
, which is what you call to say that you
have focus, and you want your parent to look for the next one.public void clearAccessibilityFocus()
focusSearch(int)
, which is what you call to say that you
have focus, and you want your parent to look for the next one.public final boolean requestFocus()
isFocusable()
returns
false), or if it is focusable and it is not focusable in touch mode
(isFocusableInTouchMode()
) while the device is in touch mode.
See also focusSearch(int)
, which is what you call to say that you
have focus, and you want your parent to look for the next one.
This is equivalent to calling requestFocus(int, Rect)
with arguments
FOCUS_DOWN
and null
.public final boolean requestFocus(int direction)
isFocusable()
returns
false), or if it is focusable and it is not focusable in touch mode
(isFocusableInTouchMode()
) while the device is in touch mode.
See also focusSearch(int)
, which is what you call to say that you
have focus, and you want your parent to look for the next one.
This is equivalent to calling requestFocus(int, Rect)
with
null
set for the previously focused rectangle.direction
- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHTpublic boolean requestFocus(int direction, Rect previouslyFocusedRect)
isFocusable()
returns
false), or if it is focusable and it is not focusable in touch mode
(isFocusableInTouchMode()
) while the device is in touch mode.
A View will not take focus if it is not visible.
A View will not take focus if one of its parents has
ViewGroup.getDescendantFocusability()
equal to
ViewGroup.FOCUS_BLOCK_DESCENDANTS
.
See also focusSearch(int)
, which is what you call to say that you
have focus, and you want your parent to look for the next one.
You may wish to override this method if your custom View
has an internal
View
that it wishes to forward the request to.direction
- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHTpreviouslyFocusedRect
- The rectangle (in this View's coordinate system)
to give a finer grained hint about where focus is coming from. May be null
if there is no hint.public final boolean requestFocusFromTouch()
requestFocus()
that will allow views that are not focusable in
touch mode to request focus when they are touched.isInTouchMode()
public int getImportantForAccessibility()
IMPORTANT_FOR_ACCESSIBILITY_YES
,
IMPORTANT_FOR_ACCESSIBILITY_NO
,
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
,
IMPORTANT_FOR_ACCESSIBILITY_AUTO
public void setAccessibilityLiveRegion(int mode)
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
.
To disable change notifications for this view, use
ACCESSIBILITY_LIVE_REGION_NONE
. This is the default live region
mode for most views.
To indicate that the user should be notified of changes, use
ACCESSIBILITY_LIVE_REGION_POLITE
.
If the view's changes should interrupt ongoing speech and notify the user
immediately, use ACCESSIBILITY_LIVE_REGION_ASSERTIVE
.
mode
- The live region mode for this view, one of:
public int getAccessibilityLiveRegion()
setAccessibilityLiveRegion(int)
public void setImportantForAccessibility(int mode)
mode
- How to determine whether this view is important for accessibility.IMPORTANT_FOR_ACCESSIBILITY_YES
,
IMPORTANT_FOR_ACCESSIBILITY_NO
,
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
,
IMPORTANT_FOR_ACCESSIBILITY_AUTO
public boolean isImportantForAccessibility()
If an ancestor of this view has importance
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
, this method
returns false
.
Otherwise, the value is computed according to the view's
getImportantForAccessibility()
value:
IMPORTANT_FOR_ACCESSIBILITY_NO
or
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
, return false
IMPORTANT_FOR_ACCESSIBILITY_YES
, return true
IMPORTANT_FOR_ACCESSIBILITY_AUTO
, return true
if
view satisfies any of the following:
isClickable()
,
isLongClickable()
, or isFocusable()
View.AccessibilityDelegate
View.OnTouchListener
,
View.OnKeyListener
, etc.
getAccessibilityLiveRegion()
is not
ACCESSIBILITY_LIVE_REGION_NONE
.
setImportantForAccessibility(int)
,
getImportantForAccessibility()
public ViewParent getParentForAccessibility()
public void addChildrenForAccessibility(ArrayList<View> outChildren)
outChildren
- The output list that will receive children for accessibility.public boolean includeForAccessibility()
public boolean isActionableForAccessibility()
public void notifyViewAccessibilityStateChangedIfNeeded(int changeType)
ViewConfiguration.getSendRecurringAccessibilityEventsInterval()
to avoid unnecessary load to the system. Also once a view has a pending
notification this method is a NOP until the notification has been sent.public void notifySubtreeAccessibilityStateChangedIfNeeded()
ViewConfiguration.getSendRecurringAccessibilityEventsInterval()
to avoid unnecessary load to the system. Also once a view has a pending
notification this method is a NOP until the notification has been sent.public void setTransitionVisibility(int visibility)
public boolean dispatchNestedPrePerformAccessibilityAction(int action, Bundle arguments)
Implementations of performAccessibilityAction(int, Bundle)
may internally
call this method to delegate an accessibility action to a supporting parent. If the parent
returns true from its
ViewParent.onNestedPrePerformAccessibilityAction(View, int, android.os.Bundle)
method this method will return true to signify that the action was consumed.
This method is useful for implementing nested scrolling child views. If
isNestedScrollingEnabled()
returns true and the action is a scrolling action
a custom view implementation may invoke this method to allow a parent to consume the
scroll first. If this method returns true the custom view should skip its own scrolling
behavior.
action
- Accessibility action to delegatearguments
- Optional action argumentspublic boolean performAccessibilityAction(int action, Bundle arguments)
AccessibilityNodeInfo
.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.performAccessibilityAction(View, int, Bundle)
is responsible for handling this call.
The default implementation will delegate
AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD
and
AccessibilityNodeInfo.ACTION_SCROLL_FORWARD
to nested scrolling parents if
nested scrolling is enabled
on this view.
action
- The action to perform.arguments
- Optional action arguments.public boolean performAccessibilityActionInternal(int action, Bundle arguments)
public CharSequence getIterableTextForAccessibility()
public boolean isAccessibilitySelectionExtendable()
public int getAccessibilitySelectionStart()
public int getAccessibilitySelectionEnd()
public void setAccessibilitySelection(int start, int end)
public AccessibilityIterators.TextSegmentIterator getIteratorForGranularity(int granularity)
public final boolean isTemporarilyDetached()
View
is in the state between onStartTemporaryDetach()
and onFinishTemporaryDetach()
.
This method always returns true
when called directly or indirectly from
onStartTemporaryDetach()
. The return value when called directly or indirectly from
onFinishTemporaryDetach()
, however, depends on the OS version.
true
when the View is in the state between onStartTemporaryDetach()
and onFinishTemporaryDetach()
.public void dispatchStartTemporaryDetach()
onStartTemporaryDetach()
to this View and its direct children if this is
a container View.public void onStartTemporaryDetach()
ViewGroup.detachViewFromParent
.
It will either be followed by onFinishTemporaryDetach()
or
onDetachedFromWindow()
when the container is done.public void dispatchFinishTemporaryDetach()
onFinishTemporaryDetach()
to this View and its direct children if this is
a container View.public void onFinishTemporaryDetach()
onStartTemporaryDetach()
when the container is done
changing the view.public KeyEvent.DispatcherState getKeyDispatcherState()
KeyEvent.DispatcherState
for this view's window. Returns null if the view is not currently attached
to the window. Normally you will not need to use this directly, but
just use the standard high-level event callbacks like
onKeyDown(int, KeyEvent)
.public boolean dispatchKeyEventPreIme(KeyEvent event)
event
- The key event to be dispatched.public boolean dispatchKeyEvent(KeyEvent event)
event
- The key event to be dispatched.public boolean dispatchKeyShortcutEvent(KeyEvent event)
event
- The key event to be dispatched.public boolean dispatchTouchEvent(MotionEvent event)
event
- The motion event to be dispatched.public boolean onFilterTouchEventForSecurity(MotionEvent event)
event
- The motion event to be filtered.getFilterTouchesWhenObscured()
public boolean dispatchTrackballEvent(MotionEvent event)
event
- The motion event to be dispatched.public boolean dispatchGenericMotionEvent(MotionEvent event)
Generic motion events with source class InputDevice.SOURCE_CLASS_POINTER
are delivered to the view under the pointer. All other generic motion events are
delivered to the focused view. Hover events are handled specially and are delivered
to onHoverEvent(MotionEvent)
.
event
- The motion event to be dispatched.protected boolean dispatchHoverEvent(MotionEvent event)
Do not call this method directly.
Call dispatchGenericMotionEvent(MotionEvent)
instead.
event
- The motion event to be dispatched.protected boolean hasHoveredChild()
MotionEvent.ACTION_HOVER_ENTER
. If this view is hovered and
it does not have a hovered child, then it must be the innermost hovered view.protected boolean dispatchGenericPointerEvent(MotionEvent event)
Do not call this method directly.
Call dispatchGenericMotionEvent(MotionEvent)
instead.
event
- The motion event to be dispatched.protected boolean dispatchGenericFocusedEvent(MotionEvent event)
Do not call this method directly.
Call dispatchGenericMotionEvent(MotionEvent)
instead.
event
- The motion event to be dispatched.public final boolean dispatchPointerEvent(MotionEvent event)
Dispatches touch related pointer events to onTouchEvent(MotionEvent)
and all
other events to onGenericMotionEvent(MotionEvent)
. This separation of concerns
reinforces the invariant that onTouchEvent(MotionEvent)
is really about touches
and should not be expected to handle other pointing device features.
event
- The motion event to be dispatched.public void dispatchWindowFocusChanged(boolean hasFocus)
hasFocus
- True if the window containing this view now has focus,
false otherwise.public void onWindowFocusChanged(boolean hasWindowFocus)
hasWindowFocus
- True if the window containing this view now has
focus, false otherwise.public boolean hasWindowFocus()
protected void dispatchVisibilityChanged(View changedView, int visibility)
protected void onVisibilityChanged(View changedView, int visibility)
public void dispatchDisplayHint(int hint)
protected void onDisplayHint(int hint)
public void dispatchWindowVisibilityChanged(int visibility)
visibility
- The new visibility of the window.onWindowVisibilityChanged(int)
protected void onWindowVisibilityChanged(int visibility)
GONE
, INVISIBLE
, and VISIBLE
). Note
that this tells you whether or not your window is being made visible
to the window manager; this does not tell you whether or not
your window is obscured by other windows on the screen, even if it
is itself visible.visibility
- The new visibility of the window.public void onVisibilityAggregated(boolean isVisible)
isVisible
- true if this view and all of its ancestors are VISIBLE
and this view's window is also visiblepublic int getWindowVisibility()
GONE
, INVISIBLE
, or VISIBLE
).public void getWindowVisibleDisplayFrame(Rect outRect)
This function requires an IPC back to the window manager to retrieve the requested information, so should not be used in performance critical code like drawing.
outRect
- Filled in with the visible display frame. If the view
is not attached to a window, this is simply the raw display size.public void getWindowDisplayFrame(Rect outRect)
getWindowVisibleDisplayFrame(android.graphics.Rect)
, but returns the "full" display frame this window
is currently in without any insets.public void dispatchConfigurationChanged(Configuration newConfig)
newConfig
- The new resource configuration.onConfigurationChanged(android.content.res.Configuration)
protected void onConfigurationChanged(Configuration newConfig)
Activity
mechanism of
recreating the activity instance upon a configuration change.newConfig
- The new resource configuration.public boolean isInTouchMode()
public final Context getContext()
public boolean onKeyPreIme(int keyCode, KeyEvent event)
keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onKeyDown(int keyCode, KeyEvent event)
KeyEvent.Callback.onKeyDown()
: perform press of the view
when KeyEvent.KEYCODE_DPAD_CENTER
or KeyEvent.KEYCODE_ENTER
is released, if the view is enabled and clickable.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
onKeyDown
in interface KeyEvent.Callback
keyCode
- a key code that represents the button pressed, from
KeyEvent
event
- the KeyEvent object that defines the button actionpublic boolean onKeyLongPress(int keyCode, KeyEvent event)
KeyEvent.Callback.onKeyLongPress()
: always returns false (doesn't handle
the event).
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
onKeyLongPress
in interface KeyEvent.Callback
keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onKeyUp(int keyCode, KeyEvent event)
KeyEvent.Callback.onKeyUp()
: perform clicking of the view
when KeyEvent.KEYCODE_DPAD_CENTER
, KeyEvent.KEYCODE_ENTER
or KeyEvent.KEYCODE_SPACE
is released.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
onKeyUp
in interface KeyEvent.Callback
keyCode
- A key code that represents the button pressed, from
KeyEvent
.event
- The KeyEvent object that defines the button action.public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
KeyEvent.Callback.onKeyMultiple()
: always returns false (doesn't handle
the event).
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
onKeyMultiple
in interface KeyEvent.Callback
keyCode
- A key code that represents the button pressed, from
KeyEvent
.repeatCount
- The number of times the action was made.event
- The KeyEvent object that defines the button action.public boolean onKeyShortcut(int keyCode, KeyEvent event)
shortcut
property of menu items.keyCode
- The value in event.getKeyCode().event
- Description of the key event.public boolean onCheckIsTextEditor()
onCreateInputConnection(EditorInfo)
to return true if
a call on that method would return a non-null InputConnection, and
they are really a first-class editor that the user would normally
start typing on when the go into a window containing your view.
The default implementation always returns false. This does
not mean that its onCreateInputConnection(EditorInfo)
will not be called or the user can not otherwise perform edits on your
view; it is just a hint to the system that this is not the primary
purpose of this view.
public InputConnection onCreateInputConnection(EditorInfo outAttrs)
When implementing this, you probably also want to implement
onCheckIsTextEditor()
to indicate you will return a
non-null InputConnection.
Also, take good care to fill in the EditorInfo
object correctly and in its entirety, so that the connected IME can rely
on its values. For example, EditorInfo.initialSelStart
and EditorInfo.initialSelEnd
members
must be filled in with the correct cursor position for IMEs to work correctly
with your application.
outAttrs
- Fill in with attribute information about the connection.public boolean checkInputConnectionProxy(View view)
InputMethodManager
when a view who is not the current
input connection target is trying to make a call on the manager. The
default implementation returns false; you can override this to return
true for certain views if you are performing InputConnection proxying
to them.view
- The View that is making the InputMethodManager call.public void createContextMenu(ContextMenu menu)
onCreateContextMenu(ContextMenu)
or define an
View.OnCreateContextMenuListener
to add items to the context menu.menu
- The context menu to populateprotected ContextMenu.ContextMenuInfo getContextMenuInfo()
OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)
callback.protected void onCreateContextMenu(ContextMenu menu)
menu
- the context menu to populatepublic boolean onTrackballEvent(MotionEvent event)
MotionEvent.getX()
and
MotionEvent.getY()
. These are normalized so
that a movement of 1 corresponds to the user pressing one DPAD key (so
they will often be fractional values, representing the more fine-grained
movement information available from a trackball).event
- The motion event.public boolean onGenericMotionEvent(MotionEvent event)
Generic motion events describe joystick movements, mouse hovers, track pad
touches, scroll wheel movements and other input events. The
source
of the motion event specifies
the class of input that was received. Implementations of this method
must examine the bits in the source before processing the event.
The following code example shows how this is done.
Generic motion events with source class InputDevice.SOURCE_CLASS_POINTER
are delivered to the view under the pointer. All other generic motion events are
delivered to the focused view.
public boolean onGenericMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... return true; } } if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: // process the mouse hover movement... return true; case MotionEvent.ACTION_SCROLL: // process the scroll wheel movement... return true; } } return super.onGenericMotionEvent(event); }
event
- The generic motion event being processed.public boolean onHoverEvent(MotionEvent event)
This method is called whenever a pointer is hovering into, over, or out of the
bounds of a view and the view is not currently being touched.
Hover events are represented as pointer events with action
MotionEvent.ACTION_HOVER_ENTER
, MotionEvent.ACTION_HOVER_MOVE
,
or MotionEvent.ACTION_HOVER_EXIT
.
MotionEvent.ACTION_HOVER_ENTER
when the pointer enters the bounds of the view.MotionEvent.ACTION_HOVER_MOVE
when the pointer has already entered the bounds of the view and has moved.MotionEvent.ACTION_HOVER_EXIT
when the pointer has exited the bounds of the view or when the pointer is
about to go down due to a button click, tap, or similar user action that
causes the view to be touched.The view should implement this method to return true to indicate that it is handling the hover event, such as by changing its drawable state.
The default implementation calls setHovered(boolean)
to update the hovered state
of the view when a hover enter or hover exit event is received, if the view
is enabled and is clickable. The default implementation also sends hover
accessibility events.
event
- The motion event that describes the hover.isHovered()
,
setHovered(boolean)
,
onHoverChanged(boolean)
public boolean isHovered()
setHovered(boolean)
,
onHoverChanged(boolean)
public void setHovered(boolean hovered)
Calling this method also changes the drawable state of the view. This enables the view to react to hover by using different drawable resources to change its appearance.
The onHoverChanged(boolean)
method is called when the hovered state changes.
hovered
- True if the view is hovered.isHovered()
,
onHoverChanged(boolean)
public void onHoverChanged(boolean hovered)
This method is called whenever the hover state changes as a result of a
call to setHovered(boolean)
.
hovered
- The current hover state, as returned by isHovered()
.isHovered()
,
setHovered(boolean)
protected boolean handleScrollBarDragging(MotionEvent event)
event
- The motion event.public boolean onTouchEvent(MotionEvent event)
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
event
- The motion event.public boolean isInScrollingContainer()
public void cancelLongPress()
public void setTouchDelegate(TouchDelegate delegate)
public TouchDelegate getTouchDelegate()
public final void requestUnbufferedDispatch(MotionEvent event)
MotionEvent.ACTION_UP
, ask that the input
system not batch MotionEvent
s but instead deliver them as soon as they're
available. This method should only be called for touch events.
This api is not intended for most applications. Buffered dispatch
provides many of benefits, and just requesting unbuffered dispatch on most MotionEvent
streams will not improve your input latency. Side effects include: increased latency,
jittery scrolls and inability to take advantage of system resampling. Talk to your input
professional to see if requestUnbufferedDispatch(MotionEvent)
is right for
you.
public void bringToFront()
Build.VERSION_CODES.KITKAT
this
method should be followed by calls to requestLayout()
and
invalidate()
on the view's parent to force the parent to redraw
with the new child ordering.ViewGroup.bringChildToFront(View)
protected void onScrollChanged(int l, int t, int oldl, int oldt)
scrollBy(int, int)
or scrollTo(int, int)
having been
called.l
- Current horizontal scroll origin.t
- Current vertical scroll origin.oldl
- Previous horizontal scroll origin.oldt
- Previous vertical scroll origin.protected void onSizeChanged(int w, int h, int oldw, int oldh)
w
- Current width of this view.h
- Current height of this view.oldw
- Old width of this view.oldh
- Old height of this view.protected void dispatchDraw(Canvas canvas)
canvas
- the canvas on which to draw the viewpublic final ViewParent getParent()
public void setScrollX(int value)
onScrollChanged(int, int, int, int)
and the view will be
invalidated.value
- the x position to scroll topublic void setScrollY(int value)
onScrollChanged(int, int, int, int)
and the view will be
invalidated.value
- the y position to scroll topublic final int getScrollX()
public final int getScrollY()
public final int getWidth()
public final int getHeight()
public void getDrawingRect(Rect outRect)
setScaleX(float)
or setRotation(float)
.outRect
- The (scrolled) drawing bounds of the view.public final int getMeasuredWidth()
getMeasuredWidthAndState()
, but only returns the
raw width component (that is the result is masked by
MEASURED_SIZE_MASK
).public final int getMeasuredWidthAndState()
measure(int, int)
. This result is a bit mask
as defined by MEASURED_SIZE_MASK
and MEASURED_STATE_TOO_SMALL
.
This should be used during measurement and layout calculations only. Use
getWidth()
to see how wide a view is after layout.public final int getMeasuredHeight()
getMeasuredHeightAndState()
, but only returns the
raw width component (that is the result is masked by
MEASURED_SIZE_MASK
).public final int getMeasuredHeightAndState()
measure(int, int)
. This result is a bit mask
as defined by MEASURED_SIZE_MASK
and MEASURED_STATE_TOO_SMALL
.
This should be used during measurement and layout calculations only. Use
getHeight()
to see how wide a view is after layout.public final int getMeasuredState()
getMeasuredWidthAndState()
and getMeasuredHeightAndState()
, combined into one integer.
The width component is in the regular bits MEASURED_STATE_MASK
and the height component is at the shifted bits
MEASURED_HEIGHT_STATE_SHIFT
>>MEASURED_STATE_MASK
.public Matrix getMatrix()
getRotation()
,
getScaleX()
,
getScaleY()
,
getPivotX()
,
getPivotY()
public final Matrix getInverseMatrix()
public float getCameraDistance()
setCameraDistance(float)
public void setCameraDistance(float distance)
Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.
The distance of the camera from the view plane can have an affect on the perspective distortion of the view when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)
The distance is expressed in "depth pixels." The default distance depends on the screen density. For instance, on a medium density display, the default distance is 1280. On a high density display, the default distance is 1920.
If you want to specify a distance that leads to visually consistent results across various densities, use the following formula:
float scale = context.getResources().getDisplayMetrics().density; view.setCameraDistance(distance * scale);
The density scale factor of a high density display is 1.5, and 1920 = 1280 * 1.5.
distance
- The distance in "depth pixels", if negative the opposite
value is usedsetRotationX(float)
,
setRotationY(float)
public float getRotation()
setRotation(float)
,
getPivotX()
,
getPivotY()
public void setRotation(float rotation)
rotation
- The degrees of rotation.getRotation()
,
getPivotX()
,
getPivotY()
,
setRotationX(float)
,
setRotationY(float)
public float getRotationY()
getPivotX()
,
getPivotY()
,
setRotationY(float)
public void setRotationY(float rotationY)
setCameraDistance(float)
for more information.rotationY
- The degrees of Y rotation.getRotationY()
,
getPivotX()
,
getPivotY()
,
setRotation(float)
,
setRotationX(float)
,
setCameraDistance(float)
public float getRotationX()
getPivotX()
,
getPivotY()
,
setRotationX(float)
public void setRotationX(float rotationX)
setCameraDistance(float)
for more information.rotationX
- The degrees of X rotation.getRotationX()
,
getPivotX()
,
getPivotY()
,
setRotation(float)
,
setRotationY(float)
,
setCameraDistance(float)
public float getScaleX()
By default, this is 1.0f.
getPivotX()
,
getPivotY()
public void setScaleX(float scaleX)
scaleX
- The scaling factor.getPivotX()
,
getPivotY()
public float getScaleY()
By default, this is 1.0f.
getPivotX()
,
getPivotY()
public void setScaleY(float scaleY)
scaleY
- The scaling factor.getPivotX()
,
getPivotY()
public float getPivotX()
getRotation()
,
getScaleX()
,
getScaleY()
,
getPivotY()
public void setPivotX(float pivotX)
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.pivotX
- The x location of the pivot point.getRotation()
,
getScaleX()
,
getScaleY()
,
getPivotY()
public float getPivotY()
getRotation()
,
getScaleX()
,
getScaleY()
,
getPivotY()
public void setPivotY(float pivotY)
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.pivotY
- The y location of the pivot point.getRotation()
,
getScaleX()
,
getScaleY()
,
getPivotY()
public float getAlpha()
By default this is 1.0f.
public void forceHasOverlappingRendering(boolean hasOverlappingRendering)
hasOverlappingRendering()
for more details on this behavior). Calling this method
is an alternative to overriding hasOverlappingRendering()
in a subclass,
providing the value which is then used internally. That is, when forceHasOverlappingRendering(boolean)
is called, the value of hasOverlappingRendering()
is ignored and the value passed into this method is used
instead.hasOverlappingRendering
- The value for overlapping rendering to be used internally
instead of that returned by hasOverlappingRendering()
.public final boolean getHasOverlappingRendering()
forceHasOverlappingRendering(boolean)
, if called, or
the return value of hasOverlappingRendering()
, otherwise.public boolean 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.
The current implementation of the saveLayer and saveLayerAlpha methods in Canvas
necessitates that a View return true if it uses the methods internally without passing the
Canvas.CLIP_TO_LAYER_SAVE_FLAG
.
Note: The return value of this method is ignored if forceHasOverlappingRendering(boolean)
has been called on this view.
public void setAlpha(float alpha)
Note: 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.
For a view with a frequently changing alpha, such as during a fading animation, it is
strongly recommended for performance reasons to either override
hasOverlappingRendering()
to return false
if appropriate, or setting a
layer type
on the view for the duration
of the animation. On versions Build.VERSION_CODES.M
and below,
the default path for rendering an unlayered View with alpha could add multiple milliseconds
of rendering cost, even for simple or small views. Starting with
Build.VERSION_CODES.M
, LAYER_TYPE_HARDWARE
is automatically
applied to the view at the rendering level.
If this view overrides onSetAlpha(int)
to return true, then this view is
responsible for applying the opacity itself.
On versions Build.VERSION_CODES.LOLLIPOP_MR1
and below, note that if
the view is backed by a layer
and is
associated with a layer paint
, setting an
alpha value less than 1.0 will supersede the alpha of the layer paint.
Starting with Build.VERSION_CODES.M
, setting a translucent alpha
value will clip a View to its bounds, unless the View returns false
from
hasOverlappingRendering()
.
alpha
- The opacity of the view.hasOverlappingRendering()
,
setLayerType(int, android.graphics.Paint)
public void setTransitionAlpha(float alpha)
public float getTransitionAlpha()
public final int getTop()
public final void setTop(int top)
top
- The top of this view, in pixels.public final int getBottom()
public boolean isDirty()
public final void setBottom(int bottom)
bottom
- The bottom of this view, in pixels.public final int getLeft()
public final void setLeft(int left)
left
- The left of this view, in pixels.public final int getRight()
public final void setRight(int right)
right
- The right of this view, in pixels.public float getX()
translationX
property plus the current
left
property.public void setX(float x)
translationX
property to be the difference between
the x value passed in and the current left
property.x
- The visual x position of this view, in pixels.public float getY()
translationY
property plus the current
top
property.public void setY(float y)
translationY
property to be the difference between
the y value passed in and the current top
property.y
- The visual y position of this view, in pixels.public float getZ()
translationZ
property plus the current
elevation
property.public void setZ(float z)
translationZ
property to be the difference between
the x value passed in and the current elevation
property.z
- The visual z position of this view, in pixels.public float getElevation()
public void setElevation(float elevation)
public float getTranslationX()
left
position.
This position is post-layout, in addition to wherever the object's
layout placed it.public void setTranslationX(float translationX)
left
position.
This effectively positions the object post-layout, in addition to wherever the object's
layout placed it.translationX
- The horizontal position of this view relative to its left position,
in pixels.public float getTranslationY()
top
position.
This position is post-layout, in addition to wherever the object's
layout placed it.public void setTranslationY(float translationY)
top
position.
This effectively positions the object post-layout, in addition to wherever the object's
layout placed it.translationY
- The vertical position of this view relative to its top position,
in pixels.public float getTranslationZ()
elevation
.public void setTranslationZ(float translationZ)
elevation
.public void setAnimationMatrix(Matrix matrix)
public StateListAnimator getStateListAnimator()
setStateListAnimator(android.animation.StateListAnimator)
public void setStateListAnimator(StateListAnimator stateListAnimator)
Any previously attached StateListAnimator will be detached.
stateListAnimator
- The StateListAnimator to update the viewandroid.animation.StateListAnimator}
public final boolean getClipToOutline()
Note that this flag will only be respected if the View's Outline returns true from
Outline.canClip()
.
public void setClipToOutline(boolean clipToOutline)
Only a single non-rectangular clip can be applied on a View at any time.
Circular clips from a circular reveal
animation take priority over Outline clipping, and
child Outline clipping takes priority over Outline clipping done by a
parent.
Note that this flag will only be respected if the View's Outline returns true from
Outline.canClip()
.
public void setOutlineProvider(ViewOutlineProvider provider)
ViewOutlineProvider
of the view, which generates the Outline that defines
the shape of the shadow it casts, and enables outline clipping.
The default ViewOutlineProvider, ViewOutlineProvider.BACKGROUND
, queries the Outline
from the View's background drawable, via Drawable.getOutline(Outline)
. Changing the
outline provider with this method allows this behavior to be overridden.
If the ViewOutlineProvider is null, if querying it for an outline returns false,
or if the produced Outline is Outline.isEmpty()
, shadows will not be cast.
Only outlines that return true from Outline.canClip()
may be used for clipping.
public ViewOutlineProvider getOutlineProvider()
ViewOutlineProvider
of the view, which generates the Outline
that defines the shape of the shadow it casts, and enables outline clipping.setOutlineProvider(ViewOutlineProvider)
public void invalidateOutline()
outline provider
setOutlineProvider(ViewOutlineProvider)
public boolean hasShadow()
public void setRevealClip(boolean shouldClip, float x, float y, float radius)
public void getHitRect(Rect outRect)
outRect
- The hit rectangle of the view.public boolean pointInView(float localX, float localY, float slop)
public void getFocusedRect(Rect r)
getDrawingRect(android.graphics.Rect)
)
of the view. However, if your view maintains some idea of internal selection,
such as a cursor, or a selected row or column, you should override this method and
fill in a more specific rectangle.r
- The rectangle to fill in, in this view's coordinates.public boolean getGlobalVisibleRect(Rect r, Point globalOffset)
r
- If true is returned, r holds the global coordinates of the
visible portion of this view.globalOffset
- If true is returned, globalOffset holds the dx,dy
between this view and its root. globalOffet may be null.public final boolean getGlobalVisibleRect(Rect r)
public final boolean getLocalVisibleRect(Rect r)
public void offsetTopAndBottom(int offset)
offset
- the number of pixels to offset the view bypublic void offsetLeftAndRight(int offset)
offset
- the number of pixels to offset the view bypublic ViewGroup.LayoutParams getLayoutParams()
setLayoutParams(android.view.ViewGroup.LayoutParams)
was not invoked successfully. When a View is attached to a parent
ViewGroup, this method must not return null.public void setLayoutParams(ViewGroup.LayoutParams params)
params
- The layout parameters for this view, cannot be nullpublic void resolveLayoutParams()
public void scrollTo(int x, int y)
onScrollChanged(int, int, int, int)
and the view will be
invalidated.x
- the x position to scroll toy
- the y position to scroll topublic void scrollBy(int x, int y)
onScrollChanged(int, int, int, int)
and the view will be
invalidated.x
- the amount of pixels to scroll by horizontallyy
- the amount of pixels to scroll by verticallyprotected boolean awakenScrollBars()
Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a default delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.
The animation starts only if at least one of the scrollbars is
enabled, as specified by isHorizontalScrollBarEnabled()
and
isVerticalScrollBarEnabled()
. When the animation is started,
this method returns true, and false otherwise. If the animation is
started, this method calls invalidate()
; in that case the
caller should not call invalidate()
.
This method should be invoked every time a subclass directly updates the scroll parameters.
This method is automatically invoked by scrollBy(int, int)
and scrollTo(int, int)
.
awakenScrollBars(int)
,
scrollBy(int, int)
,
scrollTo(int, int)
,
isHorizontalScrollBarEnabled()
,
isVerticalScrollBarEnabled()
,
setHorizontalScrollBarEnabled(boolean)
,
setVerticalScrollBarEnabled(boolean)
protected boolean awakenScrollBars(int startDelay)
Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a fixed delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.
The animation starts only if at least one of the scrollbars is enabled,
as specified by isHorizontalScrollBarEnabled()
and
isVerticalScrollBarEnabled()
. When the animation is started,
this method returns true, and false otherwise. If the animation is
started, this method calls invalidate()
; in that case the caller
should not call invalidate()
.
This method should be invoked every time a subclass directly updates the scroll parameters.
startDelay
- the delay, in milliseconds, after which the animation
should start; when the delay is 0, the animation starts
immediatelyscrollBy(int, int)
,
scrollTo(int, int)
,
isHorizontalScrollBarEnabled()
,
isVerticalScrollBarEnabled()
,
setHorizontalScrollBarEnabled(boolean)
,
setVerticalScrollBarEnabled(boolean)
protected boolean awakenScrollBars(int startDelay, boolean invalidate)
Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a fixed delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.
The animation starts only if at least one of the scrollbars is enabled,
as specified by isHorizontalScrollBarEnabled()
and
isVerticalScrollBarEnabled()
. When the animation is started,
this method returns true, and false otherwise. If the animation is
started, this method calls invalidate()
if the invalidate parameter
is set to true; in that case the caller
should not call invalidate()
.
This method should be invoked every time a subclass directly updates the scroll parameters.
startDelay
- the delay, in milliseconds, after which the animation
should start; when the delay is 0, the animation starts
immediatelyinvalidate
- Whether this method should call invalidatescrollBy(int, int)
,
scrollTo(int, int)
,
isHorizontalScrollBarEnabled()
,
isVerticalScrollBarEnabled()
,
setHorizontalScrollBarEnabled(boolean)
,
setVerticalScrollBarEnabled(boolean)
public void invalidate(Rect dirty)
onDraw(android.graphics.Canvas)
will be called at some
point in the future.
This must be called from a UI thread. To call from a non-UI thread, call
postInvalidate()
.
WARNING: In API 19 and below, this method may be destructive to
dirty
.
dirty
- the rectangle representing the bounds of the dirty regionpublic void invalidate(int l, int t, int r, int b)
onDraw(android.graphics.Canvas)
will be called at some
point in the future.
This must be called from a UI thread. To call from a non-UI thread, call
postInvalidate()
.
l
- the left position of the dirty regiont
- the top position of the dirty regionr
- the right position of the dirty regionb
- the bottom position of the dirty regionpublic void invalidate()
onDraw(android.graphics.Canvas)
will be called at some point in
the future.
This must be called from a UI thread. To call from a non-UI thread, call
postInvalidate()
.
protected void damageInParent()
protected void invalidateParentCaches()
protected void invalidateParentIfNeeded()
protected void invalidateParentIfNeededAndWasQuickRejected()
public boolean isOpaque()
protected void computeOpaqueFlags()
protected boolean hasOpaqueScrollbars()
public Handler getHandler()
public ViewRootImpl getViewRootImpl()
public ThreadedRenderer getHardwareRenderer()
public boolean post(Runnable action)
Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.
action
- The Runnable that will be executed.postDelayed(java.lang.Runnable, long)
,
removeCallbacks(java.lang.Runnable)
public boolean postDelayed(Runnable action, long delayMillis)
Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.
action
- The Runnable that will be executed.delayMillis
- The delay (in milliseconds) until the Runnable
will be executed.post(java.lang.Runnable)
,
removeCallbacks(java.lang.Runnable)
public void postOnAnimation(Runnable action)
Causes the Runnable to execute on the next animation time step. The runnable will be run on the user interface thread.
action
- The Runnable that will be executed.postOnAnimationDelayed(java.lang.Runnable, long)
,
removeCallbacks(java.lang.Runnable)
public void postOnAnimationDelayed(Runnable action, long delayMillis)
Causes the Runnable to execute on the next animation time step, after the specified amount of time elapses. The runnable will be run on the user interface thread.
action
- The Runnable that will be executed.delayMillis
- The delay (in milliseconds) until the Runnable
will be executed.postOnAnimation(java.lang.Runnable)
,
removeCallbacks(java.lang.Runnable)
public boolean removeCallbacks(Runnable action)
Removes the specified Runnable from the message queue.
action
- The Runnable to remove from the message handling queuepost(java.lang.Runnable)
,
postDelayed(java.lang.Runnable, long)
,
postOnAnimation(java.lang.Runnable)
,
postOnAnimationDelayed(java.lang.Runnable, long)
public void postInvalidate()
Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
invalidate()
,
postInvalidateDelayed(long)
public void postInvalidate(int left, int top, int right, int bottom)
Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
left
- The left coordinate of the rectangle to invalidate.top
- The top coordinate of the rectangle to invalidate.right
- The right coordinate of the rectangle to invalidate.bottom
- The bottom coordinate of the rectangle to invalidate.invalidate(int, int, int, int)
,
invalidate(Rect)
,
postInvalidateDelayed(long, int, int, int, int)
public void postInvalidateDelayed(long delayMilliseconds)
Cause an invalidate to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
delayMilliseconds
- the duration in milliseconds to delay the
invalidation byinvalidate()
,
postInvalidate()
public void postInvalidateDelayed(long delayMilliseconds, int left, int top, int right, int bottom)
Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
delayMilliseconds
- the duration in milliseconds to delay the
invalidation byleft
- The left coordinate of the rectangle to invalidate.top
- The top coordinate of the rectangle to invalidate.right
- The right coordinate of the rectangle to invalidate.bottom
- The bottom coordinate of the rectangle to invalidate.invalidate(int, int, int, int)
,
invalidate(Rect)
,
postInvalidate(int, int, int, int)
public void postInvalidateOnAnimation()
Cause an invalidate to happen on the next animation time step, typically the next display frame.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
invalidate()
public void postInvalidateOnAnimation(int left, int top, int right, int bottom)
Cause an invalidate of the specified area to happen on the next animation time step, typically the next display frame.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
left
- The left coordinate of the rectangle to invalidate.top
- The top coordinate of the rectangle to invalidate.right
- The right coordinate of the rectangle to invalidate.bottom
- The bottom coordinate of the rectangle to invalidate.invalidate(int, int, int, int)
,
invalidate(Rect)
public void computeScroll()
Scroller
object.public boolean isHorizontalFadingEdgeEnabled()
Indicate whether the horizontal edges are faded when the view is scrolled horizontally.
setHorizontalFadingEdgeEnabled(boolean)
public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
Define whether the horizontal edges should be faded when this view is scrolled horizontally.
horizontalFadingEdgeEnabled
- true if the horizontal edges should
be faded when the view is scrolled
horizontallyisHorizontalFadingEdgeEnabled()
public boolean isVerticalFadingEdgeEnabled()
Indicate whether the vertical edges are faded when the view is scrolled horizontally.
setVerticalFadingEdgeEnabled(boolean)
public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
Define whether the vertical edges should be faded when this view is scrolled vertically.
verticalFadingEdgeEnabled
- true if the vertical edges should
be faded when the view is scrolled
verticallyisVerticalFadingEdgeEnabled()
protected float getTopFadingEdgeStrength()
protected float getBottomFadingEdgeStrength()
protected float getLeftFadingEdgeStrength()
protected float getRightFadingEdgeStrength()
public boolean isHorizontalScrollBarEnabled()
Indicate whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.
setHorizontalScrollBarEnabled(boolean)
public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
Define whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.
horizontalScrollBarEnabled
- true if the horizontal scrollbar should
be paintedisHorizontalScrollBarEnabled()
public boolean isVerticalScrollBarEnabled()
Indicate whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.
setVerticalScrollBarEnabled(boolean)
public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
Define whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.
verticalScrollBarEnabled
- true if the vertical scrollbar should
be paintedisVerticalScrollBarEnabled()
protected void recomputePadding()
public void setScrollbarFadingEnabled(boolean fadeScrollbars)
fadeScrollbars
- whether to enable fadingpublic boolean isScrollbarFadingEnabled()
public int getScrollBarDefaultDelayBeforeFade()
public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade)
scrollBarDefaultDelayBeforeFade
- - the delay before scrollbars fadepublic int getScrollBarFadeDuration()
public void setScrollBarFadeDuration(int scrollBarFadeDuration)
scrollBarFadeDuration
- - the scrollbar fade durationpublic int getScrollBarSize()
public void setScrollBarSize(int scrollBarSize)
scrollBarSize
- - the scrollbar sizepublic void setScrollBarStyle(int style)
Specify the style of the scrollbars. The scrollbars can be overlaid or inset. When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.
style
- the style of the scrollbars. Should be one of
SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET,
SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.SCROLLBARS_INSIDE_OVERLAY
,
SCROLLBARS_INSIDE_INSET
,
SCROLLBARS_OUTSIDE_OVERLAY
,
SCROLLBARS_OUTSIDE_INSET
public int getScrollBarStyle()
Returns the current scrollbar style.
SCROLLBARS_INSIDE_OVERLAY
,
SCROLLBARS_INSIDE_INSET
,
SCROLLBARS_OUTSIDE_OVERLAY
,
SCROLLBARS_OUTSIDE_INSET
protected int computeHorizontalScrollRange()
Compute the horizontal range that the horizontal scrollbar represents.
The range is expressed in arbitrary units that must be the same as the
units used by computeHorizontalScrollExtent()
and
computeHorizontalScrollOffset()
.
The default range is the drawing width of this view.
computeHorizontalScrollExtent()
,
computeHorizontalScrollOffset()
,
ScrollBarDrawable
protected int computeHorizontalScrollOffset()
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the
units used by computeHorizontalScrollRange()
and
computeHorizontalScrollExtent()
.
The default offset is the scroll offset of this view.
computeHorizontalScrollRange()
,
computeHorizontalScrollExtent()
,
ScrollBarDrawable
protected int computeHorizontalScrollExtent()
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the
units used by computeHorizontalScrollRange()
and
computeHorizontalScrollOffset()
.
The default extent is the drawing width of this view.
computeHorizontalScrollRange()
,
computeHorizontalScrollOffset()
,
ScrollBarDrawable
protected int computeVerticalScrollRange()
Compute the vertical range that the vertical scrollbar represents.
The range is expressed in arbitrary units that must be the same as the
units used by computeVerticalScrollExtent()
and
computeVerticalScrollOffset()
.
The default range is the drawing height of this view.
computeVerticalScrollExtent()
,
computeVerticalScrollOffset()
,
ScrollBarDrawable
protected int computeVerticalScrollOffset()
Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the
units used by computeVerticalScrollRange()
and
computeVerticalScrollExtent()
.
The default offset is the scroll offset of this view.
computeVerticalScrollRange()
,
computeVerticalScrollExtent()
,
ScrollBarDrawable
protected int computeVerticalScrollExtent()
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the
units used by computeVerticalScrollRange()
and
computeVerticalScrollOffset()
.
The default extent is the drawing height of this view.
computeVerticalScrollRange()
,
computeVerticalScrollOffset()
,
ScrollBarDrawable
public boolean canScrollHorizontally(int direction)
direction
- Negative to check scrolling left, positive to check scrolling right.public boolean canScrollVertically(int direction)
direction
- Negative to check scrolling up, positive to check scrolling down.protected final void onDrawScrollBars(Canvas canvas)
Request the drawing of the horizontal and the vertical scrollbar. The scrollbars are painted only if they have been awakened first.
canvas
- the canvas on which to draw the scrollbarsawakenScrollBars(int)
protected boolean isVerticalScrollBarHidden()
protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t, int r, int b)
Draw the horizontal scrollbar if
isHorizontalScrollBarEnabled()
returns true.
canvas
- the canvas on which to draw the scrollbarscrollBar
- the scrollbar's drawableisHorizontalScrollBarEnabled()
,
computeHorizontalScrollRange()
,
computeHorizontalScrollExtent()
,
computeHorizontalScrollOffset()
,
ScrollBarDrawable
protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t, int r, int b)
Draw the vertical scrollbar if isVerticalScrollBarEnabled()
returns true.
canvas
- the canvas on which to draw the scrollbarscrollBar
- the scrollbar's drawableisVerticalScrollBarEnabled()
,
computeVerticalScrollRange()
,
computeVerticalScrollExtent()
,
computeVerticalScrollOffset()
,
ScrollBarDrawable
protected void onDraw(Canvas canvas)
canvas
- the canvas on which the background will be drawnprotected void onAttachedToWindow()
onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after onMeasure(int, int)
.onDetachedFromWindow()
public boolean resolveRtlPropertiesIfNeeded()
public void resetRtlProperties()
public void onScreenStateChanged(int screenState)
screenState
- The new state of the screen. Can be either
SCREEN_STATE_ON
or SCREEN_STATE_OFF
public void onRtlPropertiesChanged(int layoutDirection)
layoutDirection
- the direction of the layoutLAYOUT_DIRECTION_LTR
,
LAYOUT_DIRECTION_RTL
public boolean resolveLayoutDirection()
public boolean canResolveLayoutDirection()
public void resetResolvedLayoutDirection()
onMeasure(int, int)
.public boolean isLayoutDirectionInherited()
public boolean isLayoutDirectionResolved()
public void resolvePadding()
public void resetResolvedPadding()
protected void onDetachedFromWindow()
onAttachedToWindow()
protected void onDetachedFromWindowInternal()
protected int getWindowAttachCount()
public IBinder getWindowToken()
WindowManager.LayoutParams.token
.public WindowId getWindowId()
WindowId
for the window this view is
currently attached to.public IBinder getApplicationWindowToken()
getWindowToken()
, except if the window this view in is a panel
window (attached to another containing window), then the token of
the containing window is returned instead.getWindowToken()
or the containing window's token.public Display getDisplay()
public final void cancelPendingInputEvents()
Many views post high-level events such as click handlers to the event queue to run deferred in order to preserve a desired user experience - clearing visible pressed states before executing, etc. This method will abort any events of this nature that are currently in flight.
Custom views that generate their own high-level deferred input events should override
onCancelPendingInputEvents()
and remove those pending events from the queue.
This will also cancel pending input events for any child views.
Note that this may not be sufficient as a debouncing strategy for clicks in all cases.
This will not impact newer events posted after this call that may occur as a result of
lower-level input events still waiting in the queue. If you are trying to prevent
double-submitted events for the duration of some sort of asynchronous transaction
you should also take other steps to protect against unexpected double inputs e.g. calling
setEnabled(false)
and re-enabling the view when
the transaction completes, tracking already submitted transaction IDs, etc.
public void onCancelPendingInputEvents()
cancelPendingInputEvents()
on this view or
a parent view.
This method is responsible for removing any pending high-level input events that were
posted to the event queue to run later. Custom view classes that post their own deferred
high-level events via post(Runnable)
, postDelayed(Runnable, long)
or
Handler
should override this method, call
super.onCancelPendingInputEvents()
and remove those callbacks as appropriate.
public void saveHierarchyState(SparseArray<Parcelable> container)
container
- The SparseArray in which to save the view's state.restoreHierarchyState(android.util.SparseArray)
,
dispatchSaveInstanceState(android.util.SparseArray)
,
onSaveInstanceState()
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container)
saveHierarchyState(android.util.SparseArray)
to store the state for
this view and its children. May be overridden to modify how freezing happens to a
view's children; for example, some views may want to not store state for their children.container
- The SparseArray in which to save the view's state.dispatchRestoreInstanceState(android.util.SparseArray)
,
saveHierarchyState(android.util.SparseArray)
,
onSaveInstanceState()
protected Parcelable onSaveInstanceState()
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
onRestoreInstanceState(android.os.Parcelable)
,
saveHierarchyState(android.util.SparseArray)
,
dispatchSaveInstanceState(android.util.SparseArray)
,
setSaveEnabled(boolean)
public void restoreHierarchyState(SparseArray<Parcelable> container)
container
- The SparseArray which holds previously frozen states.saveHierarchyState(android.util.SparseArray)
,
dispatchRestoreInstanceState(android.util.SparseArray)
,
onRestoreInstanceState(android.os.Parcelable)
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container)
restoreHierarchyState(android.util.SparseArray)
to retrieve the
state for this view and its children. May be overridden to modify how restoring
happens to a view's children; for example, some views may want to not store state
for their children.container
- The SparseArray which holds previously saved state.dispatchSaveInstanceState(android.util.SparseArray)
,
restoreHierarchyState(android.util.SparseArray)
,
onRestoreInstanceState(android.os.Parcelable)
protected void onRestoreInstanceState(Parcelable state)
onSaveInstanceState()
. This function will never be called with a
null state.state
- The frozen state that had previously been returned by
onSaveInstanceState()
.onSaveInstanceState()
,
restoreHierarchyState(android.util.SparseArray)
,
dispatchRestoreInstanceState(android.util.SparseArray)
public long getDrawingTime()
Return the time at which the drawing of the view hierarchy started.
public void setDuplicateParentStateEnabled(boolean enabled)
Enables or disables the duplication of the parent's state into this view. When duplication is enabled, this view gets its drawable state from its parent rather than from its own internal properties.
Note: in the current implementation, setting this property to true after the view was added to a ViewGroup might have no effect at all. This property should always be used from XML or set to true before adding this view to a ViewGroup.
Note: if this view's parent addStateFromChildren property is enabled and this property is enabled, an exception will be thrown.
Note: if the child view uses and updates additional states which are unknown to the parent, these states should not be affected by this method.
enabled
- True to enable duplication of the parent's drawable state, false
to disable it.getDrawableState()
,
isDuplicateParentStateEnabled()
public boolean isDuplicateParentStateEnabled()
Indicates whether this duplicates its drawable state from its parent.
getDrawableState()
,
setDuplicateParentStateEnabled(boolean)
public void setLayerType(int layerType, Paint paint)
Specifies the type of layer backing this view. The layer can be
LAYER_TYPE_NONE
, LAYER_TYPE_SOFTWARE
or
LAYER_TYPE_HARDWARE
.
A layer is associated with an optional Paint
instance that controls how the layer is composed on screen. The following
properties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by calling
setAlpha(float)
, the alpha value of the layer's paint is superseded
by this view's alpha value.
Refer to the documentation of LAYER_TYPE_NONE
,
LAYER_TYPE_SOFTWARE
and LAYER_TYPE_HARDWARE
for more information on when and how to use layers.
layerType
- The type of layer to use with this view, must be one of
LAYER_TYPE_NONE
, LAYER_TYPE_SOFTWARE
or
LAYER_TYPE_HARDWARE
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
getLayerType()
,
LAYER_TYPE_NONE
,
LAYER_TYPE_SOFTWARE
,
LAYER_TYPE_HARDWARE
,
setAlpha(float)
public void setLayerPaint(Paint paint)
Paint
object used with the current layer (used only if the current
layer type is not set to LAYER_TYPE_NONE
). Changed properties of the Paint
provided to setLayerType(int, android.graphics.Paint)
will be used the next time
the View is redrawn, but setLayerPaint(android.graphics.Paint)
must be called to
ensure that the view gets redrawn immediately.
A layer is associated with an optional Paint
instance that controls how the layer is composed on screen. The following
properties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by calling setAlpha(float)
, the
alpha value of the layer's paint is superseded by this view's alpha value.
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
setLayerType(int, android.graphics.Paint)
public int getLayerType()
LAYER_TYPE_NONE
.
Refer to the documentation of setLayerType(int, android.graphics.Paint)
for more information on the different types of layers.public void buildLayer()
LAYER_TYPE_NONE
,
invoking this method will have no effect.
This method can for instance be used to render a view into its layer before
starting an animation. If this view is complex, rendering into the layer
before starting the animation will avoid skipping frames.IllegalStateException
- If this view is not attached to a windowsetLayerType(int, android.graphics.Paint)
protected void destroyHardwareResources()
super.destroyHardwareResources()
when overriding
this method.public void setDrawingCacheEnabled(boolean enabled)
Enables or disables the drawing cache. When the drawing cache is enabled, the next call
to getDrawingCache()
or buildDrawingCache()
will draw the view in a
bitmap. Calling draw(android.graphics.Canvas)
will not draw from the cache when
the cache is enabled. To benefit from the cache, you must request the drawing cache by
calling getDrawingCache()
and draw it on screen if the returned bitmap is not
null.
Enabling the drawing cache is similar to
setting a layer
when hardware
acceleration is turned off. When hardware acceleration is turned on, enabling the
drawing cache has no effect on rendering because the system uses a different mechanism
for acceleration which ignores the flag. If you want to use a Bitmap for the view, even
when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint)
for information on how to enable software and hardware layers.
This API can be used to manually generate
a bitmap copy of this view, by setting the flag to true
and calling
getDrawingCache()
.
enabled
- true to enable the drawing cache, false otherwiseisDrawingCacheEnabled()
,
getDrawingCache()
,
buildDrawingCache()
,
setLayerType(int, android.graphics.Paint)
public boolean isDrawingCacheEnabled()
Indicates whether the drawing cache is enabled for this view.
setDrawingCacheEnabled(boolean)
,
getDrawingCache()
public void outputDirtyFlags(String indent, boolean clear, int clearMask)
protected void dispatchGetDisplayList()
public boolean canHaveDisplayList()
public RenderNode updateDisplayListIfDirty()
public void onRenderNodeDetached(RenderNode renderNode)
public Bitmap getDrawingCache()
Calling this method is equivalent to calling getDrawingCache(false)
.
getDrawingCache(boolean)
public Bitmap getDrawingCache(boolean autoScale)
Returns the bitmap in which this view drawing is cached. The returned bitmap
is null when caching is disabled. If caching is enabled and the cache is not ready,
this method will create it. Calling draw(android.graphics.Canvas)
will not
draw from the cache when the cache is enabled. To benefit from the cache, you must
request the drawing cache by calling this method and draw it on screen if the
returned bitmap is not null.
Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.
autoScale
- Indicates whether the generated bitmap should be scaled based on
the current density of the screen when the application is in compatibility
mode.setDrawingCacheEnabled(boolean)
,
isDrawingCacheEnabled()
,
buildDrawingCache(boolean)
,
destroyDrawingCache()
public void destroyDrawingCache()
Frees the resources used by the drawing cache. If you call
buildDrawingCache()
manually without calling
setDrawingCacheEnabled(true)
, you
should cleanup the cache with this method afterwards.
public void setDrawingCacheBackgroundColor(int color)
color
- The background color to use for the drawing cache's bitmapsetDrawingCacheEnabled(boolean)
,
buildDrawingCache()
,
getDrawingCache()
public int getDrawingCacheBackgroundColor()
setDrawingCacheBackgroundColor(int)
public void buildDrawingCache()
Calling this method is equivalent to calling buildDrawingCache(false)
.
buildDrawingCache(boolean)
public void buildDrawingCache(boolean autoScale)
Forces the drawing cache to be built if the drawing cache is invalid.
If you call buildDrawingCache()
manually without calling
setDrawingCacheEnabled(true)
, you
should cleanup the cache by calling destroyDrawingCache()
afterwards.
Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.
You should avoid calling this method when hardware acceleration is enabled. If you do not need the drawing cache bitmap, calling this method will increase memory usage and cause the view to be rendered in software once, thus negatively impacting performance.
getDrawingCache()
,
destroyDrawingCache()
public Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren)
public boolean isInEditMode()
protected boolean isPaddingOffsetRequired()
getLeftPaddingOffset()
,
getRightPaddingOffset()
,
getTopPaddingOffset()
,
getBottomPaddingOffset()
protected int getLeftPaddingOffset()
isPaddingOffsetRequired()
returns true.isPaddingOffsetRequired()
protected int getRightPaddingOffset()
isPaddingOffsetRequired()
returns true.isPaddingOffsetRequired()
protected int getTopPaddingOffset()
isPaddingOffsetRequired()
returns true.isPaddingOffsetRequired()
protected int getBottomPaddingOffset()
isPaddingOffsetRequired()
returns true.isPaddingOffsetRequired()
protected int getFadeTop(boolean offsetRequired)
offsetRequired
- protected int getFadeHeight(boolean offsetRequired)
offsetRequired
- public boolean isHardwareAccelerated()
Indicates whether this view is attached to a hardware accelerated window or not.
Even if this method returns true, it does not mean that every call
to draw(android.graphics.Canvas)
will be made with an hardware
accelerated Canvas
. For instance, if this view
is drawn onto an offscreen Bitmap
and its
window is hardware accelerated,
Canvas.isHardwareAccelerated()
will likely
return false, and this method will return true.
public void setClipBounds(Rect clipBounds)
clipBounds
- The rectangular area, in the local coordinates of
this view, to which future drawing operations will be clipped.public Rect getClipBounds()
clipBounds
.public boolean getClipBounds(Rect outRect)
true
if successful or false
if the view's
clip bounds are null
.outRect
- rectangle in which to place the clip bounds of the viewtrue
if successful or false
if the view's
clip bounds are null
public void draw(Canvas canvas)
onDraw(android.graphics.Canvas)
instead of overriding this method.
If you do need to override this method, call the superclass version.canvas
- The Canvas to which the View is rendered.public ViewOverlay getOverlay()
Note: Overlays do not currently work correctly with SurfaceView
or TextureView
; contents in overlays for these
types of views may not display correctly.
ViewOverlay
public int getSolidColor()
setVerticalFadingEdgeEnabled(boolean)
,
setHorizontalFadingEdgeEnabled(boolean)
public boolean isLayoutRequested()
Indicates whether or not this view's layout will be requested during the next hierarchy layout pass.
public static boolean isLayoutModeOptical(Object o)
public void layout(int l, int t, int r, int b)
This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().
Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.
l
- Left position, relative to parentt
- Top position, relative to parentr
- Right position, relative to parentb
- Bottom position, relative to parentprotected void onLayout(boolean changed, int left, int top, int right, int bottom)
changed
- This is a new size or position for this viewleft
- Left position, relative to parenttop
- Top position, relative to parentright
- Right position, relative to parentbottom
- Bottom position, relative to parentprotected boolean setFrame(int left, int top, int right, int bottom)
left
- Left position, relative to parenttop
- Top position, relative to parentright
- Right position, relative to parentbottom
- Bottom position, relative to parentpublic void setLeftTopRightBottom(int left, int top, int right, int bottom)
ChangeBounds
.protected void onFinishInflate()
Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.
public Resources getResources()
public void invalidateDrawable(Drawable drawable)
invalidateDrawable
in interface Drawable.Callback
drawable
- the drawable to invalidatepublic void scheduleDrawable(Drawable who, Runnable what, long when)
scheduleDrawable
in interface Drawable.Callback
who
- the recipient of the actionwhat
- the action to run on the drawablewhen
- the time at which the action must occur. Uses the
SystemClock.uptimeMillis()
timebase.public void unscheduleDrawable(Drawable who, Runnable what)
unscheduleDrawable
in interface Drawable.Callback
who
- the recipient of the actionwhat
- the action to cancelpublic void unscheduleDrawable(Drawable who)
who
- The Drawable to unschedule.drawableStateChanged()
protected void resolveDrawables()
onResolveDrawables(int)
when resolution is done.public void onResolveDrawables(int layoutDirection)
layoutDirection
- The resolved layout direction.LAYOUT_DIRECTION_LTR
,
LAYOUT_DIRECTION_RTL
protected void resetResolvedDrawables()
protected boolean verifyDrawable(Drawable who)
Be sure to call through to the super class when overriding this function.
who
- The Drawable to verify. Return true if it is one you are
displaying, else return the result of calling through to the
super class.unscheduleDrawable(android.graphics.drawable.Drawable)
,
drawableStateChanged()
protected void drawableStateChanged()
If the View has a StateListAnimator, it will also be called to run necessary state change animations.
Be sure to call through to the superclass when overriding this function.
Drawable.setState(int[])
public void drawableHotspotChanged(float x, float y)
Dispatching to child views is handled by
dispatchDrawableHotspotChanged(float, float)
.
Be sure to call through to the superclass when overriding this function.
x
- hotspot x coordinatey
- hotspot y coordinatepublic void dispatchDrawableHotspotChanged(float x, float y)
x
- hotspot x coordinatey
- hotspot y coordinatedrawableHotspotChanged(float, float)
public void refreshDrawableState()
drawableStateChanged()
,
getDrawableState()
public final int[] getDrawableState()
Drawable.setState(int[])
,
drawableStateChanged()
,
onCreateDrawableState(int)
protected int[] onCreateDrawableState(int extraSpace)
Drawable
state for
this view. This is called by the view
system when the cached Drawable state is determined to be invalid. To
retrieve the current state, you should use getDrawableState()
.extraSpace
- if non-zero, this is the number of extra entries you
would like in the returned array in which you can place your own
states.Drawable
state of
the view.mergeDrawableStates(int[], int[])
protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState)
onCreateDrawableState(int)
.baseState
- The base state values returned by
onCreateDrawableState(int)
, which will be modified to also hold your
own additional state values.additionalState
- The additional state values you would like
added to baseState; this array is not modified.onCreateDrawableState(int)
public void jumpDrawablesToCurrentState()
Drawable.jumpToCurrentState()
on all Drawable objects associated with this view.
Also calls StateListAnimator.jumpToCurrentState()
if there is a StateListAnimator
attached to this view.
public void setBackgroundColor(int color)
color
- the color of the backgroundpublic void setBackgroundResource(@DrawableRes int resid)
resid
- The identifier of the resource.public void setBackground(Drawable background)
setPadding(int, int, int, int)
.background
- The Drawable to use as the background, or null to remove the
background@Deprecated public void setBackgroundDrawable(Drawable background)
setBackground(Drawable)
insteadpublic Drawable getBackground()
setBackground(Drawable)
public void setBackgroundTintList(ColorStateList tint)
PorterDuff.Mode#SRC_IN
by default.
Subsequent calls to setBackground(Drawable)
will automatically
mutate the drawable and apply the specified tint and tint mode using
Drawable.setTintList(ColorStateList)
.
tint
- the tint to apply, may be null
to clear tintgetBackgroundTintList()
,
Drawable.setTintList(ColorStateList)
public ColorStateList getBackgroundTintList()
setBackgroundTintList(ColorStateList)
public void setBackgroundTintMode(PorterDuff.Mode tintMode)
setBackgroundTintList(ColorStateList)
} to the background
drawable. The default mode is PorterDuff.Mode#SRC_IN
.tintMode
- the blending mode used to apply the tint, may be
null
to clear tintgetBackgroundTintMode()
,
Drawable.setTintMode(PorterDuff.Mode)
public PorterDuff.Mode getBackgroundTintMode()
setBackgroundTintMode(PorterDuff.Mode)
public Drawable getForeground()
onDrawForeground(Canvas)
public void setForeground(Drawable foreground)
foreground
- the Drawable to be drawn on top of the childrenpublic boolean isForegroundInsidePadding()
public int getForegroundGravity()
setForegroundGravity(int)
public void setForegroundGravity(int gravity)
gravity
- see Gravity
getForegroundGravity()
public void setForegroundTintList(ColorStateList tint)
PorterDuff.Mode#SRC_IN
by default.
Subsequent calls to setForeground(Drawable)
will automatically
mutate the drawable and apply the specified tint and tint mode using
Drawable.setTintList(ColorStateList)
.
tint
- the tint to apply, may be null
to clear tintgetForegroundTintList()
,
Drawable.setTintList(ColorStateList)
public ColorStateList getForegroundTintList()
setForegroundTintList(ColorStateList)
public void setForegroundTintMode(PorterDuff.Mode tintMode)
setForegroundTintList(ColorStateList)
} to the background
drawable. The default mode is PorterDuff.Mode#SRC_IN
.tintMode
- the blending mode used to apply the tint, may be
null
to clear tintgetForegroundTintMode()
,
Drawable.setTintMode(PorterDuff.Mode)
public PorterDuff.Mode getForegroundTintMode()
setForegroundTintMode(PorterDuff.Mode)
public void onDrawForeground(Canvas canvas)
Foreground content may consist of scroll bars, a foreground
drawable or other view-specific decorations. The foreground is drawn on top of the
primary view content.
canvas
- canvas to draw intopublic void setPadding(int left, int top, int right, int bottom)
getPaddingLeft()
, getPaddingTop()
,
getPaddingRight()
and getPaddingBottom()
may be different
from the values set in this call.left
- the left padding in pixelstop
- the top padding in pixelsright
- the right padding in pixelsbottom
- the bottom padding in pixelsprotected void internalSetPadding(int left, int top, int right, int bottom)
public void setPaddingRelative(int start, int top, int end, int bottom)
getPaddingStart()
, getPaddingTop()
,
getPaddingEnd()
and getPaddingBottom()
may be different
from the values set in this call.start
- the start padding in pixelstop
- the top padding in pixelsend
- the end padding in pixelsbottom
- the bottom padding in pixelspublic int getPaddingTop()
public int getPaddingBottom()
public int getPaddingLeft()
public int getPaddingStart()
public int getPaddingRight()
public int getPaddingEnd()
public boolean isPaddingRelative()
setPaddingRelative(int, int, int, int)
or throughpublic void resetPaddingToInitialValues()
public Insets getOpticalInsets()
public void setOpticalInsets(Insets insets)
This method should be treated similarly to setMeasuredDimension and not as a general property. Views that compute their own optical insets should call it as part of measurement. This method does not request layout. If you are setting optical insets outside of measure/layout itself you will want to call requestLayout() yourself.
public void setSelected(boolean selected)
selected
- true if the view must be selected, false otherwiseprotected void dispatchSetSelected(boolean selected)
selected
- The new selected statesetSelected(boolean)
public boolean isSelected()
public void setActivated(boolean activated)
activated
- true if the view must be activated, false otherwiseprotected void dispatchSetActivated(boolean activated)
activated
- The new activated statesetActivated(boolean)
public boolean isActivated()
public ViewTreeObserver getViewTreeObserver()
ViewTreeObserver.isAlive()
.public View getRootView()
Finds the topmost view in the current view hierarchy.
public boolean toGlobalMotionEvent(MotionEvent ev)
ev
- the view-local motion eventpublic boolean toLocalMotionEvent(MotionEvent ev)
ev
- the on-screen motion eventpublic void transformMatrixToGlobal(Matrix m)
m
- input matrix to modifypublic void transformMatrixToLocal(Matrix m)
m
- input matrix to modifypublic int[] getLocationOnScreen()
public void getLocationOnScreen(int[] outLocation)
Computes the coordinates of this view on the screen. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.
outLocation
- an array of two integers in which to hold the coordinatespublic void getLocationInWindow(int[] outLocation)
Computes the coordinates of this view in its window. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.
outLocation
- an array of two integers in which to hold the coordinatespublic void transformFromViewToWindowSpace(int[] inOutLocation)
protected View findViewTraversal(@IdRes int id)
id
- the id of the view to be foundprotected View findViewWithTagTraversal(Object tag)
tag
- the tag of the view to be foundprotected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip)
predicate
- The predicate to evaluate.childToSkip
- If not null, ignores this child during the recursive traversal.public final View findViewById(@IdRes int id)
id
- The id to search for.public View findViewByAccessibilityIdTraversal(int accessibilityId)
accessibilityId
- The accessibility id.public final View findViewWithTag(Object tag)
tag
- The tag to search for, using "tag.equals(getTag())".public final View findViewByPredicate(Predicate<View> predicate)
predicate
- The predicate to evaluate.public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate)
start
- The view to start from.predicate
- The predicate to evaluate.public void setId(@IdRes int id)
id
- a number used to identify the viewNO_ID
,
getId()
,
findViewById(int)
public void setIsRootNamespace(boolean isRoot)
isRoot
- true if the view belongs to the root namespace, false
otherwisepublic boolean isRootNamespace()
@IdRes public int getId()
NO_ID
if the view has no IDsetId(int)
,
findViewById(int)
public Object getTag()
null
if not
setsetTag(Object)
,
getTag(int)
public void setTag(Object tag)
tag
- an Object to tag the view withgetTag()
,
setTag(int, Object)
public Object getTag(int key)
key
- The key identifying the tagnull
if not
setsetTag(int, Object)
,
getTag()
public void setTag(int key, Object tag)
IllegalArgumentException
to be thrown.key
- The key identifying the tagtag
- An Object to tag the view withIllegalArgumentException
- If they specified key is not validsetTag(Object)
,
getTag(int)
public void setTagInternal(int key, Object tag)
setTag(int, Object)
that enforces the key to be a
framework id.public void debug()
VIEW_LOG_TAG
.protected void debug(int depth)
VIEW_LOG_TAG
. Each line in the output is preceded with an
indentation defined by the depth
.depth
- the indentation levelprotected static String debugIndent(int depth)
depth
- the indentation levelpublic int getBaseline()
Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.
public boolean isInLayout()
requestLayout()
during
a layout pass.public void requestLayout()
isInLayout()
. If layout is happening, the request may be honored at the
end of the current layout pass (and then layout will run again) or after the current
frame is drawn and the next layout occurs.
Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.
public void forceLayout()
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be. The parent supplies constraint information in the width and height parameters.
The actual measurement work of a view is performed in
onMeasure(int, int)
, called by this method. Therefore, only
onMeasure(int, int)
can and must be overridden by subclasses.
widthMeasureSpec
- Horizontal space requirements as imposed by the
parentheightMeasureSpec
- Vertical space requirements as imposed by the
parentonMeasure(int, int)
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
and
should be overridden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (getSuggestedMinimumHeight()
and
getSuggestedMinimumWidth()
).
widthMeasureSpec
- horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.heightMeasureSpec
- vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.getMeasuredWidth()
,
getMeasuredHeight()
,
setMeasuredDimension(int, int)
,
getSuggestedMinimumHeight()
,
getSuggestedMinimumWidth()
,
View.MeasureSpec.getMode(int)
,
View.MeasureSpec.getSize(int)
protected final void setMeasuredDimension(int measuredWidth, int measuredHeight)
This method must be called by onMeasure(int, int)
to store the
measured width and measured height. Failing to do so will trigger an
exception at measurement time.
measuredWidth
- The measured width of this view. May be a complex
bit mask as defined by MEASURED_SIZE_MASK
and
MEASURED_STATE_TOO_SMALL
.measuredHeight
- The measured height of this view. May be a complex
bit mask as defined by MEASURED_SIZE_MASK
and
MEASURED_STATE_TOO_SMALL
.public static int combineMeasuredStates(int curState, int newState)
getMeasuredState()
.curState
- The current state as returned from a view or the result
of combining multiple views.newState
- The new view state to combine.public static int resolveSize(int size, int measureSpec)
resolveSizeAndState(int, int, int)
returning only the MEASURED_SIZE_MASK
bits of the result.public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
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.size
- How big the view wants to be.measureSpec
- Constraints imposed by the parent.childMeasuredState
- Size information bit mask for the view's
children.MEASURED_SIZE_MASK
and
MEASURED_STATE_TOO_SMALL
.public static int getDefaultSize(int size, int measureSpec)
size
- Default size for this viewmeasureSpec
- Constraints imposed by the parentprotected int getSuggestedMinimumHeight()
Drawable.getMinimumHeight()
).
When being used in onMeasure(int, int)
, the caller should still
ensure the returned height is within the requirements of the parent.
protected int getSuggestedMinimumWidth()
Drawable.getMinimumWidth()
).
When being used in onMeasure(int, int)
, the caller should still
ensure the returned width is within the requirements of the parent.
public int getMinimumHeight()
setMinimumHeight(int)
public void setMinimumHeight(int minHeight)
minHeight
- The minimum height the view will try to be.getMinimumHeight()
public int getMinimumWidth()
setMinimumWidth(int)
public void setMinimumWidth(int minWidth)
minWidth
- The minimum width the view will try to be.getMinimumWidth()
public Animation getAnimation()
public void startAnimation(Animation animation)
animation
- the animation to start nowpublic void clearAnimation()
public void setAnimation(Animation animation)
startAnimation(android.view.animation.Animation)
instead.
This method provides allows fine-grained
control over the start time and invalidation, but you
must make sure that 1) the animation has a start time set, and
2) the view's parent (which controls animations on its children)
will be invalidated when the animation is supposed to
start.animation
- The next animation, or null.protected void onAnimationStart()
protected void onAnimationEnd()
protected boolean onSetAlpha(int alpha)
alpha
- The alpha (0..255) to apply to the view's drawingpublic boolean gatherTransparentRegion(Region region)
region
- The transparent region for this ViewAncestor (window).public void playSoundEffect(int soundConstant)
The framework will play sound effects for some built in actions, such as clicking, but you may wish to play these effects in your widget, for instance, for internal navigation.
The sound effect will only be played if sound effects are enabled by the user, and
isSoundEffectsEnabled()
is true.
soundConstant
- One of the constants defined in SoundEffectConstants
public boolean performHapticFeedback(int feedbackConstant)
Provide haptic feedback to the user for this view.
The framework will provide haptic feedback for some built in actions, such as long presses, but you may wish to provide feedback for your own widget.
The feedback will only be performed if
isHapticFeedbackEnabled()
is true.
feedbackConstant
- One of the constants defined in
HapticFeedbackConstants
public boolean performHapticFeedback(int feedbackConstant, int flags)
Like performHapticFeedback(int)
, with additional options.
feedbackConstant
- One of the constants defined in
HapticFeedbackConstants
flags
- Additional flags as per HapticFeedbackConstants
.public void setSystemUiVisibility(int visibility)
This method is used to put the over device UI into temporary modes
where the user's attention is focused more on the application content,
by dimming or hiding surrounding system affordances. This is typically
used in conjunction with Window.FEATURE_ACTION_BAR_OVERLAY
, allowing the applications content
to be placed behind the action bar (and with these flags other system
affordances) so that smooth transitions between hiding and showing them
can be done.
Two representative examples of the use of system UI visibility is implementing a content browsing application (like a magazine reader) and a video playing application.
The first code shows a typical implementation of a View in a content browsing application. In this implementation, the application goes into a content-oriented mode by hiding the status bar and action bar, and putting the navigation elements into lights out mode. The user can then interact with content while in this mode. Such an application should provide an easy way for the user to toggle out of the mode (such as to check information in the status bar or access notifications). In the implementation here, this is done simply by tapping on the content.
This second code sample shows a typical implementation of a View
in a video playing application. In this situation, while the video is
playing the application would like to go into a complete full-screen mode,
to use as much of the display as possible for the video. When in this state
the user can not interact with the application; the system intercepts
touching on the screen to pop the UI out of full screen mode. See
fitSystemWindows(Rect)
for a sample layout that goes with this code.
visibility
- Bitwise-or of flags SYSTEM_UI_FLAG_LOW_PROFILE
,
SYSTEM_UI_FLAG_HIDE_NAVIGATION
, SYSTEM_UI_FLAG_FULLSCREEN
,
SYSTEM_UI_FLAG_LAYOUT_STABLE
, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
,
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
, SYSTEM_UI_FLAG_IMMERSIVE
,
and SYSTEM_UI_FLAG_IMMERSIVE_STICKY
.public int getSystemUiVisibility()
setSystemUiVisibility(int)
that this view has requested.public int getWindowSystemUiVisibility()
setSystemUiVisibility(int)
values supplied by all of the
views in the window.public void onWindowSystemUiVisibilityChanged(int visible)
getWindowSystemUiVisibility()
.
This is different from the callbacks received through
setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)
in that this is only telling you about the local request of the window,
not the actual values applied by the system.public void dispatchWindowSystemUiVisiblityChanged(int visible)
onWindowSystemUiVisibilityChanged(int)
down
the view hierarchy.public void setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener l)
l
- The View.OnSystemUiVisibilityChangeListener
to receive callbacks.public void dispatchSystemUiVisibilityChanged(int visibility)
setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener)
down
the view hierarchy.public void setDisabledSystemUiVisibility(int flags)
public final boolean startDrag(ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)
startDragAndDrop()
for newer platform versions.public final boolean startDragAndDrop(ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)
View.DragShadowBuilder
object to the system. The
system calls this object's View.DragShadowBuilder.onProvideShadowMetrics(Point, Point)
to get metrics for the drag shadow, and then calls the object's
View.DragShadowBuilder.onDrawShadow(Canvas)
to draw the drag shadow itself.
Once the system has the drag shadow, it begins the drag and drop operation by sending
drag events to all the View objects in your application that are currently visible. It does
this either by calling the View object's drag listener (an implementation of
onDrag()
or by calling the
View object's onDragEvent()
method.
Both are passed a DragEvent
object that has a
DragEvent.getAction()
value of
DragEvent.ACTION_DRAG_STARTED
.
Your application can invoke startDragAndDrop()
on any attached View object. The View object does not need to be
the one used in View.DragShadowBuilder
, nor does it need to be related
to the View the user selected for dragging.
data
- A ClipData
object pointing to the data to be
transferred by the drag and drop operation.shadowBuilder
- A View.DragShadowBuilder
object for building the
drag shadow.myLocalState
- An Object
containing local data about the drag and
drop operation. When dispatching drag events to views in the same activity this object
will be available through DragEvent.getLocalState()
. Views in other
activities will not have access to this data (DragEvent.getLocalState()
will return null).
myLocalState is a lightweight mechanism for the sending information from the dragged View to the target Views. For example, it can contain flags that differentiate between a a copy operation and a move operation.
flags
- Flags that control the drag and drop operation. This can be set to 0 for no
flags, or any combination of the following:
true
if the method completes successfully, or
false
if it fails anywhere. Returning false
means the system was unable to
do a drag, and so no drag operation is in progress.public final void cancelDragAndDrop()
A DragEvent
object with
DragEvent.getAction()
value of
DragEvent.ACTION_DRAG_ENDED
and
DragEvent.getResult()
value of false
will be sent to every
View that received DragEvent.ACTION_DRAG_STARTED
even if they are not currently visible.
This method can be called on any View in the same window as the View on which
startDragAndDrop
was called.
public final void updateDragShadow(View.DragShadowBuilder shadowBuilder)
shadowBuilder
- A View.DragShadowBuilder
object for building the
new drag shadow.public final boolean startMovingTask(float startX, float startY)
startX
- horizontal coordinate where the move started.startY
- vertical coordinate where the move started.public boolean onDragEvent(DragEvent event)
startDragAndDrop()
.
When the system calls this method, it passes a
DragEvent
object. A call to
DragEvent.getAction()
returns one of the action type constants defined
in DragEvent. The method uses these to determine what is happening in the drag and drop
operation.
event
- The DragEvent
sent by the system.
The DragEvent.getAction()
method returns an action type constant defined
in DragEvent, indicating the type of drag event represented by this object.true
if the method was successful, otherwise false
.
The method should return true
in response to an action type of
DragEvent.ACTION_DRAG_STARTED
to receive drag events for the current
operation.
The method should also return true
in response to an action type of
DragEvent.ACTION_DROP
if it consumed the drop, or
false
if it didn't.
public boolean dispatchDragEvent(DragEvent event)
DragEvent
it received. If the drag event listener returns
true
, then dispatchDragEvent() returns true
.
For all other cases, the method calls the
onDragEvent()
drag event handler
method and returns its result.
This ensures that a drag event is always consumed, even if the View does not have a drag event listener. However, if the View has a listener and the listener returns true, then onDragEvent() is not called.
public void onCloseSystemDialogs(String reason)
public void applyDrawableToTransparentRegion(Drawable dr, Region region)
gatherTransparentRegion(android.graphics.Region)
so
that any non-transparent parts of the Drawable are removed from the
given transparent region.dr
- The Drawable whose transparency is to be applied to the region.region
- A Region holding the current transparency information,
where any parts of the region that are set are considered to be
transparent. On return, this region will be modified to have the
transparency information reduced by the corresponding parts of the
Drawable that are not transparent.
public static View inflate(Context context, @LayoutRes int resource, ViewGroup root)
LayoutInflater
class, which provides a full range of options for view inflation.context
- The Context object for your activity or application.resource
- The resource ID to inflateroot
- A view group that will be the parent. Used to properly inflate the
layout_* parameters.LayoutInflater
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)
onOverScrolled(int, int, boolean, boolean)
to respond to the
results of an over-scroll operation.
Views can use this method to handle any touch or fling-based scrolling.deltaX
- Change in X in pixelsdeltaY
- Change in Y in pixelsscrollX
- Current X scroll value in pixels before applying deltaXscrollY
- Current Y scroll value in pixels before applying deltaYscrollRangeX
- Maximum content scroll range along the X axisscrollRangeY
- Maximum content scroll range along the Y axismaxOverScrollX
- Number of pixels to overscroll by in either direction
along the X axis.maxOverScrollY
- Number of pixels to overscroll by in either direction
along the Y axis.isTouchEvent
- true if this scroll operation is the result of a touch event.protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY)
overScrollBy(int, int, int, int, int, int, int, int, boolean)
to
respond to the results of an over-scroll operation.scrollX
- New X scroll value in pixelsscrollY
- New Y scroll value in pixelsclampedX
- True if scrollX was clamped to an over-scroll boundaryclampedY
- True if scrollY was clamped to an over-scroll boundarypublic int getOverScrollMode()
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
.public void setOverScrollMode(int overScrollMode)
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.overScrollMode
- The new over-scroll mode for this view.public void setNestedScrollingEnabled(boolean enabled)
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.
enabled
- true to enable nested scrolling, false to disableisNestedScrollingEnabled()
public boolean 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.
setNestedScrollingEnabled(boolean)
public boolean startNestedScroll(int axes)
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 MotionEvent.ACTION_DOWN
.
In the case of touch scrolling the nested scroll will be terminated automatically in
the same manner as ViewParent.requestDisallowInterceptTouchEvent(boolean)
.
In the event of programmatic scrolling the caller must explicitly call
stopNestedScroll()
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.
After applying the remainder of the scroll delta the caller should invoke
dispatchNestedScroll
, passing
both the delta consumed and the delta unconsumed. A nested scrolling parent may treat
these values differently. See ViewParent.onNestedScroll(View, int, int, int, int)
.
axes
- Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL
and/or
SCROLL_AXIS_VERTICAL
.stopNestedScroll()
,
dispatchNestedPreScroll(int, int, int[], int[])
,
dispatchNestedScroll(int, int, int, int, int[])
public void stopNestedScroll()
Calling this method when a nested scroll is not currently in progress is harmless.
startNestedScroll(int)
public boolean hasNestedScrollingParent()
The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
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.
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- 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.dispatchNestedPreScroll(int, int, int[], int[])
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)
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.
dx
- Horizontal scroll distance in pixelsdy
- Vertical scroll distance in pixelsconsumed
- Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy.offsetInWindow
- 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.dispatchNestedScroll(int, int, int, int, int[])
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
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.
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondconsumed
- true if the child consumed the fling, false otherwisepublic boolean dispatchNestedPreFling(float velocityX, float velocityY)
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:
dispatchNestedPreFling
; consume the fling and settle to a valid
position regardless.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.
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondprotected float getVerticalScrollFactor()
MotionEvent.ACTION_SCROLL
.protected float getHorizontalScrollFactor()
MotionEvent.ACTION_SCROLL
.public int getRawTextDirection()
setTextDirection(int)
.TEXT_DIRECTION_INHERIT
,
TEXT_DIRECTION_FIRST_STRONG
,
TEXT_DIRECTION_ANY_RTL
,
TEXT_DIRECTION_LTR
,
TEXT_DIRECTION_RTL
,
TEXT_DIRECTION_LOCALE
,
TEXT_DIRECTION_FIRST_STRONG_LTR
,
TEXT_DIRECTION_FIRST_STRONG_RTL
public void setTextDirection(int textDirection)
textDirection
- the direction to set. Should be one of:
TEXT_DIRECTION_INHERIT
,
TEXT_DIRECTION_FIRST_STRONG
,
TEXT_DIRECTION_ANY_RTL
,
TEXT_DIRECTION_LTR
,
TEXT_DIRECTION_RTL
,
TEXT_DIRECTION_LOCALE
TEXT_DIRECTION_FIRST_STRONG_LTR
,
TEXT_DIRECTION_FIRST_STRONG_RTL
,
Resolution will be done if the value is set to TEXT_DIRECTION_INHERIT. The resolution
proceeds up the parent chain of the view to get the value. If there is no parent, then it will
return the default TEXT_DIRECTION_FIRST_STRONG
.public int getTextDirection()
TEXT_DIRECTION_FIRST_STRONG
,
TEXT_DIRECTION_ANY_RTL
,
TEXT_DIRECTION_LTR
,
TEXT_DIRECTION_RTL
,
TEXT_DIRECTION_LOCALE
,
TEXT_DIRECTION_FIRST_STRONG_LTR
,
TEXT_DIRECTION_FIRST_STRONG_RTL
public boolean resolveTextDirection()
public boolean canResolveTextDirection()
public void resetResolvedTextDirection()
onMeasure(int, int)
.public boolean isTextDirectionInherited()
public boolean isTextDirectionResolved()
public int getRawTextAlignment()
setTextAlignment(int)
.TEXT_ALIGNMENT_INHERIT
,
TEXT_ALIGNMENT_GRAVITY
,
TEXT_ALIGNMENT_CENTER
,
TEXT_ALIGNMENT_TEXT_START
,
TEXT_ALIGNMENT_TEXT_END
,
TEXT_ALIGNMENT_VIEW_START
,
TEXT_ALIGNMENT_VIEW_END
public void setTextAlignment(int textAlignment)
textAlignment
- The text alignment to set. Should be one of
TEXT_ALIGNMENT_INHERIT
,
TEXT_ALIGNMENT_GRAVITY
,
TEXT_ALIGNMENT_CENTER
,
TEXT_ALIGNMENT_TEXT_START
,
TEXT_ALIGNMENT_TEXT_END
,
TEXT_ALIGNMENT_VIEW_START
,
TEXT_ALIGNMENT_VIEW_END
Resolution will be done if the value is set to TEXT_ALIGNMENT_INHERIT. The resolution
proceeds up the parent chain of the view to get the value. If there is no parent, then it
will return the default TEXT_ALIGNMENT_GRAVITY
.public int getTextAlignment()
TEXT_ALIGNMENT_GRAVITY
,
TEXT_ALIGNMENT_CENTER
,
TEXT_ALIGNMENT_TEXT_START
,
TEXT_ALIGNMENT_TEXT_END
,
TEXT_ALIGNMENT_VIEW_START
,
TEXT_ALIGNMENT_VIEW_END
public boolean resolveTextAlignment()
public boolean canResolveTextAlignment()
public void resetResolvedTextAlignment()
onMeasure(int, int)
.public boolean isTextAlignmentInherited()
public boolean isTextAlignmentResolved()
public static int generateViewId()
setId(int)
.
This value will not collide with ID values generated at build time by aapt for R.id.public void captureTransitioningViews(List<View> transitioningViews)
transitioningViews
- This View will be added to transitioningViews if it is VISIBLE and
a normal View or a ViewGroup with
ViewGroup.isTransitionGroup()
true.public void findNamedViews(Map<String,View> namedElements)
getTransitionName()
non-null to namedElements.namedElements
- Will contain all Views in the hierarchy having a transitionName.public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex)
event
- The MotionEvent from a mousepointerIndex
- The index of the pointer for which to retrieve the PointerIcon
.
This will be between 0 and MotionEvent.getPointerCount()
.PointerIcon
public void setPointerIcon(PointerIcon pointerIcon)
null
will restore the pointer icon to its default value.pointerIcon
- A PointerIcon instance which will be shown when the mouse hovers.public PointerIcon getPointerIcon()
public ViewPropertyAnimator animate()
public final void setTransitionName(String transitionName)
transitionName
- The name of the View to uniquely identify it for Transitions.public String getTransitionName()
This returns null if the View has not been given a name.
public void requestKeyboardShortcuts(List<KeyboardShortcutGroup> data, int deviceId)
public void encode(ViewHierarchyEncoder stream)
protected void encodeProperties(ViewHierarchyEncoder stream)