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 intiate 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 rendering each view that
intersects the invalid region. Because the tree is traversed in-order,
this means that parents will draw 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 for you
before calling back to its onDraw()
method.
Note that the framework will not draw views that are not in the invalid region.
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.
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 class |
View.MeasureSpec
A MeasureSpec encapsulates the layout requirements passed from parent to child.
|
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.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.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.
|
Modifier and Type | Field and Description |
---|---|
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 |
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_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.
|
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 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 |
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 |
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.
|
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_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_LAYOUT_FULLSCREEN
Flag for
setSystemUiVisibility(int) : View would like its window
to be layed 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 layed 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_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 |
TEXT_ALIGNMENT_CENTER
Center the paragraph, e.g.
|
static int |
TEXT_ALIGNMENT_GRAVITY
Default for the root view.
|
static int |
TEXT_ALIGNMENT_INHERIT |
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_INHERIT
Text direction is inherited thru
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. |
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
|
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 defStyle)
Perform inflation from XML and apply a class-specific base style.
|
Modifier and Type | Method and Description |
---|---|
void |
addChildrenForAccessibility(ArrayList<View> children)
Adds the children of a given View for accessibility.
|
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 |
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 |
cancelLongPress()
Cancels a pending long press.
|
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 |
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.
|
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 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.
|
protected int |
computeVerticalScrollExtent()
Compute the vertical extent of the horizontal 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 . |
void |
createContextMenu(ContextMenu menu)
Show the context menu for this view.
|
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.
|
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 |
dispatchFinishTemporaryDetach() |
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 |
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. |
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() |
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.
|
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.
|
View |
findFocus()
Find the view in the hierarchy rooted at this view that currently has
focus.
|
View |
findViewById(int id)
Look for a child view with the given id.
|
View |
findViewByPredicate(com.android.internal.util.Predicate<View> predicate)
Look for a child view that matches the specified predicate.
|
View |
findViewByPredicateInsideOut(View start,
com.android.internal.util.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(com.android.internal.util.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)
Called by the view hierarchy when the content insets for a window have
changed, to allow it to adjust its content to fit within those windows.
|
View |
focusSearch(int direction)
Find the nearest view in the specified direction that can take focus.
|
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) . |
int |
getAccessibilityCursorPosition() |
View.AccessibilityDelegate |
getAccessibilityDelegate()
Returns the delegate for implementing accessibility support via
composition.
|
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 |
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
|
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.
|
float |
getCameraDistance()
Gets the distance along the Z axis from the camera to this view.
|
CharSequence |
getContentDescription()
Gets the
View 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.
|
DisplayList |
getDisplayList()
Returns a display list that can be used to draw this view again
without executing its draw method.
|
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.
|
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 {@link #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.
|
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() |
HardwareRenderer |
getHardwareRenderer() |
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 . |
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.
|
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 |
getLocationInWindow(int[] location)
Computes the coordinates of this view in its window.
|
void |
getLocationOnScreen(int[] location)
Computes the coordinates of this view on the screen.
|
Matrix |
getMatrix()
The transform matrix of this view, which is calculated based on the current
roation, 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() |
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()
|
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.
|
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.
|
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 |
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.
|
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 {@link #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 |
getTranslationX()
The horizontal location of this view relative to its
left position. |
float |
getTranslationY()
The horizontal location of this view relative to its
top position. |
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() |
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.
|
void |
hackTurnOffWindowResizeAnim(boolean off) |
boolean |
hasFocus()
Returns true if this view has focus iteself, 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 |
hasOnClickListeners()
Return whether this view has an attached OnClickListener.
|
protected boolean |
hasOpaqueScrollbars() |
boolean |
hasOverlappingRendering()
Returns whether this View has content which overlaps.
|
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 |
initializeScrollbars(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.
|
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.
|
boolean |
isActionableForAccessibility()
Returns whether the View is considered actionable from
accessibility perspective.
|
boolean |
isActivated()
Indicates the activation state of this view.
|
boolean |
isClickable()
Indicates whether this view reacts to click events 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 |
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()
Gets whether this view should be exposed for accessibility.
|
boolean |
isInEditMode()
Indicates whether this View is currently in edit mode.
|
boolean |
isInScrollingContainer() |
boolean |
isInTouchMode()
Returns whether the device is currently in touch mode.
|
boolean |
isLayoutDirectionInherited() |
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 |
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 as been set thru relative values
setPaddingRelative(int, int, int, int) or thru |
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 |
isTextAlignmentInherited() |
boolean |
isTextDirectionInherited() |
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
|
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 |
notifyAccessibilityStateChanged()
Notifies accessibility services that some view's important for
accessibility state has 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.
|
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.
|
protected void |
onAttachedToWindow()
This is called when the view is attached to a window.
|
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 |
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
startDrag() . |
protected void |
onDraw(Canvas canvas)
Implement this to do your drawing.
|
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 |
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an
AccessibilityNodeInfo with information about this view. |
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 or
KeyEvent.KEYCODE_ENTER 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 |
onResolveDrawables(int layoutDirection)
Called when layout direction has been resolved.
|
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.
|
protected void |
onVisibilityChanged(View changedView,
int visibility)
Called when the visibility of the view or an ancestor of the view is 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.
|
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 |
performHapticFeedback(int feedbackConstant)
BZZZTT!!1!
|
boolean |
performHapticFeedback(int feedbackConstant,
int flags)
BZZZTT!!1!
|
boolean |
performLongClick()
Call this view's OnLongClickListener, if it is defined.
|
void |
playSoundEffect(int soundConstant)
Play a sound effect for this view.
|
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 |
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 |
requestFitSystemWindows()
Ask that a new dispatch of
fitSystemWindows(Rect) be performed. |
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 |
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 |
resetAccessibilityStateChanged()
Reset the state indicating the this view has requested clients
interested in its accessibility state to be notified.
|
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()
Resolve padding depending on layout direction.
|
void |
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 |
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 |
setAccessibilityCursorPosition(int position) |
void |
setAccessibilityDelegate(View.AccessibilityDelegate delegate)
Sets a delegate for implementing accessibility support via composition as
opposed to inheritance.
|
void |
setActivated(boolean activated)
Changes the activated state of this view.
|
void |
setAlpha(float alpha)
Sets the opacity of the view.
|
void |
setAnimation(Animation animation)
Sets the next animation to play for this view.
|
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 |
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 |
setContentDescription(CharSequence contentDescription)
Sets the
View description. |
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 |
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.
|
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 |
setLayoutInsets(Insets layoutInsets) |
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 |
setLongClickable(boolean longClickable)
Enables or disables long click events for this view.
|
protected void |
setMeasuredDimension(int measuredWidth,
int measuredHeight)
This mehod 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 |
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 |
setOnClickListener(View.OnClickListener l)
Register a callback to be invoked when this view is 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 |
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 |
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 |
setPressed(boolean pressed)
Sets the pressed state for this view.
|
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 |
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 |
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 |
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 |
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 enabled 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.
|
boolean |
showContextMenu()
Bring up the context menu for this view.
|
boolean |
showContextMenu(float x,
float y,
int metaState)
Bring up the context menu for this view, referring to the item under the specified point.
|
ActionMode |
startActionMode(ActionMode.Callback callback)
Start an action mode.
|
void |
startAnimation(Animation animation)
Start the specified animation now.
|
boolean |
startDrag(ClipData data,
View.DragShadowBuilder shadowBuilder,
Object myLocalState,
int flags)
Starts a drag and drop operation.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
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.
|
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 final int NO_ID
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_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_ALIGNMENT_INHERIT
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 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).public 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.
public 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.
public 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.
public 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 layed 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 navagation 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 layed 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 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 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
represeting the virtual views with this text.public static final int SCREEN_STATE_OFF
public static final int SCREEN_STATE_ON
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 boolean mCachingFailed
public static final int DRAG_FLAG_GLOBAL
startDrag(ClipData, DragShadowBuilder, Object, int)
is called
with this flag set, all visible applications will be able to participate
in the drag operation and receive the dragged content.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.
protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier
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> 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 defStyle)
R.attr.buttonStyle
for defStyle; 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.defStyle
- The default style to apply to this view. If 0, no style
will be applied (beyond what is included in the theme). This may
either be an attribute resource, whose value will be retrieved
from the current theme, or an explicit style resource.View(Context, AttributeSet)
public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
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 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 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 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 setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)
l
- The callback that will runpublic 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()
protected boolean performButtonActionOnTouchDown(MotionEvent event)
event
- The event.public boolean showContextMenu()
public boolean showContextMenu(float x, float y, int metaState)
x
- The referenced x coordinate.y
- The referenced y coordinate.metaState
- The keyboard modifiers that were pressed.public ActionMode startActionMode(ActionMode.Callback callback)
callback
- Callback that will control the lifecycle of the action modeActionMode
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 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.
rectangle
- The rectangle.public 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.
When immediate
is set to true, scrolling will not be
animated.
rectangle
- The rectangle.immediate
- 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 wich 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
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 resuest 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 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 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 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 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 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 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)
,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.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
.delegate
- The delegate instance.View.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
description. It briefly describes the view and is
primarily used for accessibility support. Set this property to enable
better accessibility support for your application. This is especially
true for views that do not have textual representation (For example,
ImageButton).public void setContentDescription(CharSequence contentDescription)
View
description. It briefly describes the view and is
primarily used for accessibility support. Set this property to enable
better accessibility support for your application. This is especially
true for views that do not have textual representation (For example,
ImageButton).contentDescription
- The content description.public int getLabelFor()
public void setLabelFor(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)
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
inset's 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.getFitsSystemWindows()
,
setFitsSystemWindows(boolean)
,
setSystemUiVisibility(int)
public 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()
fitSystemWindows(Rect)
will be executed.#setFitsSystemWindows()
,
fitSystemWindows(Rect)
,
setSystemUiVisibility(int)
public boolean fitsSystemWindows()
public void requestFitSystemWindows()
fitSystemWindows(Rect)
be performed.public void makeOptionalFitsSystemWindows()
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 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 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 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 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 focuable 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_AUTO
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_AUTO
public boolean isImportantForAccessibility()
public ViewParent getParentForAccessibility()
public void addChildrenForAccessibility(ArrayList<View> children)
children
- The list of children for accessibility.public boolean includeForAccessibility()
public boolean isActionableForAccessibility()
public void notifyAccessibilityStateChanged()
ViewConfiguration.getSendRecurringAccessibilityEventsInterval()
to avoid unnecessary load to the system. Also once a view has
made a notifucation this method is a NOP until the notification has
been sent to clients.public void resetAccessibilityStateChanged()
public 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.
action
- The action to perform.arguments
- Optional action arguments.public CharSequence getIterableTextForAccessibility()
public int getAccessibilityCursorPosition()
public void setAccessibilityCursorPosition(int position)
public AccessibilityIterators.TextSegmentIterator getIteratorForGranularity(int granularity)
public void dispatchStartTemporaryDetach()
public void onStartTemporaryDetach()
ViewGroup.detachViewFromParent
.
It will either be followed by onFinishTemporaryDetach()
or
onDetachedFromWindow()
when the container is done.public void dispatchFinishTemporaryDetach()
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 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 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 action.public 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
or
KeyEvent.KEYCODE_ENTER
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.
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.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... return true; } } if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { 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)
public boolean onTouchEvent(MotionEvent event)
event
- The motion event.public boolean isInScrollingContainer()
public void cancelLongPress()
public void setTouchDelegate(TouchDelegate delegate)
public TouchDelegate getTouchDelegate()
public void bringToFront()
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 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 boolean hasOverlappingRendering()
public void setAlpha(float alpha)
Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.
If this view overrides onSetAlpha(int)
to return true, then this view is
responsible for applying the opacity itself. Otherwise, calling this method is
equivalent to calling setLayerType(int, android.graphics.Paint)
and
setting a hardware layer.
Note that setting alpha to a translucent value (0 < alpha < 1) may have performance implications. it is generally best to use the alpha property sparingly and transiently, as in the case of fading animations.
alpha
- The opacity of the view.setLayerType(int, android.graphics.Paint)
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 bottom of this view, in pixels.public final int getRight()
public final void setRight(int right)
right
- The bottom 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 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 void getHitRect(Rect outRect)
outRect
- The hit rectangle of the view.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 numer 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 everytime 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 everytime 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
- Wheter 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: This method is 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 invalidateParentCaches()
protected void invalidateParentIfNeeded()
public boolean isOpaque()
protected void computeOpaqueFlags()
protected boolean hasOpaqueScrollbars()
public Handler getHandler()
public ViewRootImpl getViewRootImpl()
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
- wheter 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 horizontal 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 void 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 void resolvePadding()
public void resetResolvedPadding()
protected void onDetachedFromWindow()
onAttachedToWindow()
protected int getWindowAttachCount()
public IBinder getWindowToken()
WindowManager.LayoutParams.token
.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 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 additionnal 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
disabled
, software
or
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 replaced by
this view's alpha value. Calling setAlpha(float)
is therefore
equivalent to setting a hardware layer on this view and providing a paint with
the desired alpha value.
Refer to the documentation of disabled
,
software
and 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 replaced by
this view's alpha value. Calling setAlpha(float)
is therefore
equivalent to setting a hardware layer on this view and providing a paint with
the desired alpha value.
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 HardwareRenderer getHardwareRenderer()
public DisplayList getDisplayList()
Returns a display list that can be used to draw this view again without executing its draw method.
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 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 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 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 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 parentprotected 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()
Be sure to call through to the superclass when overriding this function.
Drawable.setState(int[])
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.public void setBackgroundColor(int color)
color
- the color of the backgroundpublic void setBackgroundResource(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 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 thrupublic void resetPaddingToInitialValues()
public Insets getOpticalInsets()
public void setLayoutInsets(Insets layoutInsets)
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 void getLocationOnScreen(int[] location)
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.
location
- an array of two integers in which to hold the coordinatespublic void getLocationInWindow(int[] location)
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.
location
- an array of two integers in which to hold the coordinatesprotected View findViewTraversal(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(com.android.internal.util.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(int id)
id
- The id to search for.public final View findViewWithTag(Object tag)
tag
- The tag to search for, using "tag.equals(getTag())".public final View findViewByPredicate(com.android.internal.util.Predicate<View> predicate)
predicate
- The predicate to evaluate.public final View findViewByPredicateInsideOut(View start, com.android.internal.util.Predicate<View> predicate)
start
- The view to start from.predicate
- The predicate to evaluate.public void setId(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()
public int getId()
NO_ID
if the view has no IDsetId(int)
,
findViewById(int)
public Object getTag()
setTag(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 tagsetTag(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 void requestLayout()
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 overriden 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 mehod 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 bemeasureSpec
- Constraints imposed by the parentMEASURED_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
,
and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
.public int getSystemUiVisibility()
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 recieved 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)
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 startDrag() 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. This Object is put into every DragEvent object sent by the system during the
current drag.
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. No flags are currently defined,
so the parameter should be set to 0.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 boolean onDragEvent(DragEvent event)
startDrag()
.
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, 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.protected 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
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
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
public boolean resolveTextDirection()
public void resetResolvedTextDirection()
onMeasure(int, int)
.public boolean isTextDirectionInherited()
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 void resetResolvedTextAlignment()
onMeasure(int, int)
.public boolean isTextAlignmentInherited()
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 hackTurnOffWindowResizeAnim(boolean off)
public ViewPropertyAnimator animate()