java.lang.Object
   ↳ android.view.View
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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 an introduction to using this class to develop your application's user interface, read the Developer Guide documentation on User Interface. Special topics include:
Declaring Layout
Creating Menus
Common Layout Objects
Binding to Data with AdapterView
Handling UI Events
Applying Styles and Themes
Building Custom Components
How Android Draws Views.

Using Views

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:

  • Set properties: for example setting the text of a 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.
  • Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus().
  • Set up listeners: Views allow clients to set listeners that will be notified when something interesting happens to the view. For example, all views will let you set a listener to be notified when the view gains or loses focus. You can register such a listener using setOnFocusChangeListener(View.OnFocusChangeListener). Other view subclasses offer more specialized listeners. For example, a Button exposes a listener to notify clients when the button is clicked.
  • Set visibility: You can hide or show views using 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.

Implementing a Custom View

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.
onFinishInflate() Called after a view and all of its children has been inflated from XML.
Layout onMeasure(int, int) Called to determine the size requirements for this view and all of its children.
onLayout(boolean, int, int, int, int) Called when this view should assign a size and position to all of its children.
onSizeChanged(int, int, int, int) Called when the size of this view has changed.
Drawing onDraw(Canvas) Called when the view should render its content.
Event processing onKeyDown(int, KeyEvent) Called when a new key event occurs.
onKeyUp(int, KeyEvent) Called when a key up event occurs.
onTrackballEvent(MotionEvent) Called when a trackball motion event occurs.
onTouchEvent(MotionEvent) Called when a touch screen motion event occurs.
Focus onFocusChanged(boolean, int, Rect) Called when the view gains or loses focus.
onWindowFocusChanged(boolean) Called when the window containing the view gains or loses focus.
Attaching onAttachedToWindow() Called when the view is attached to a window.
onDetachedFromWindow() Called when the view is detached from its window.
onWindowVisibilityChanged(int) Called when the visibility of the window containing the view has changed.

IDs

Views may have an integer id associated with them. These ids are typically assigned in the layout XML files, and are used to find specific views within the view tree. A common pattern is to:
  • Define a Button in the layout file and assign it a unique ID.
     <Button
         android:id="@+id/my_button"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/my_button_text"/>
     
  • From the onCreate method of an Activity, find the Button
          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.

Position

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.)

Size, padding and margins

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) method and queried by calling getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom().

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

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:

  • an exact number
  • MATCH_PARENT, which means the view wants to be as big as its parent (minus padding)
  • WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding).
There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.

MeasureSpecs are used to push requirements down the tree from parent to child. A MeasureSpec can be in one of three modes:

  • UNSPECIFIED: This is used by a parent to determine the desired dimension of a child view. For example, a LinearLayout may call measure() on its child with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how tall the child view wants to be given a width of 240 pixels.
  • EXACTLY: This is used by the parent to impose an exact size on the child. The child must use this size, and guarantee that all of its descendants will fit within this size.
  • AT_MOST: This is used by the parent to impose a maximum size on the child. The child must gurantee that it and all of its descendants will fit within this size.

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

Drawing is handled by walking the tree and rendering each view that intersects the 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().

Event Handling and Threading

The basic cycle of a view is as follows:

  1. An event comes in and is dispatched to the appropriate view. The view handles the event and notifies any listeners.
  2. If in the course of processing the event, the view's bounds may need to be changed, the view will call requestLayout().
  3. Similarly, if in the course of processing the event the view's appearance may need to be changed, the view will call invalidate().
  4. If either 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.

Focus Handling

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().

Touch Mode

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 Activitys. Call isInTouchMode() to see whether the device is currently in touch mode.

Scrolling

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.

Tags

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.

Animation

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.

Starting with Android 3.0, the preferred way of animating views is to use the android.animation package APIs.

Security

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 FLAG_WINDOW_IS_OBSCURED.

See Also

Summary

Nested Classes
class View.BaseSavedState Base class for derived classes that want to save and restore their own state in onSaveInstanceState()
class View.DragShadowBuilder Creates an image that the system displays during the drag and drop operation. 
class View.MeasureSpec A MeasureSpec encapsulates the layout requirements passed from parent to child. 
interface View.OnAttachStateChangeListener Interface definition for a callback to be invoked when this view is attached or detached from its window. 
interface View.OnClickListener Interface definition for a callback to be invoked when a view is clicked. 
interface View.OnCreateContextMenuListener Interface definition for a callback to be invoked when the context menu for this view is being built. 
interface View.OnDragListener Interface definition for a callback to be invoked when a drag is being dispatched to this view. 
interface View.OnFocusChangeListener Interface definition for a callback to be invoked when the focus state of a view changed. 
interface View.OnGenericMotionListener Interface definition for a callback to be invoked when a generic motion event is dispatched to this view. 
interface View.OnKeyListener Interface definition for a callback to be invoked when a key event is dispatched to this view. 
interface View.OnLayoutChangeListener Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing. 
interface View.OnLongClickListener Interface definition for a callback to be invoked when a view has been clicked and held. 
interface View.OnSystemUiVisibilityChangeListener Interface definition for a callback to be invoked when the status bar changes visibility. 
interface View.OnTouchListener Interface definition for a callback to be invoked when a touch event is dispatched to this view. 
XML Attributes
Attribute Name Related Method Description
android:alpha setAlpha(float) alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). 
android:background setBackgroundResource(int) A drawable to use as the background. 
android:clickable setClickable(boolean) Defines whether this view reacts to click events. 
android:contentDescription setContentDescription(CharSequence) Defines text that briefly describes content of the view. 
android:drawingCacheQuality setDrawingCacheQuality(int) Defines the quality of translucent drawing caches. 
android:duplicateParentState When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself. 
android:fadingEdge setVerticalFadingEdgeEnabled(boolean) Defines which edges should be fadeded on scrolling. 
android:fadingEdgeLength getVerticalFadingEdgeLength() Defines the length of the fading edges. 
android:filterTouchesWhenObscured setFilterTouchesWhenObscured(boolean) Specifies whether to filter touches when the view's window is obscured by another visible window. 
android:fitsSystemWindows Boolean internal attribute to adjust view layout based on system windows such as the status bar. 
android:focusable setFocusable(boolean) Boolean that controls whether a view can take focus. 
android:focusableInTouchMode setFocusableInTouchMode(boolean) Boolean that controls whether a view can take focus while in touch mode. 
android:hapticFeedbackEnabled setHapticFeedbackEnabled(boolean) Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. 
android:id setId(int) Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById()
android:isScrollContainer Set this if the view will serve as a scrolling container, meaing that it can be resized to shrink its overall window so that there will be space for an input method. 
android:keepScreenOn setKeepScreenOn(boolean) Controls whether the view's window should keep the screen on while visible. 
android:layerType setLayerType(int,Paint) Specifies the type of layer backing this view. 
android:longClickable setLongClickable(boolean) Defines whether this view reacts to long click events. 
android:minHeight Defines the minimum height of the view. 
android:minWidth Defines the minimum width of the view. 
android:nextFocusDown setNextFocusDownId(int) Defines the next view to give focus to when the next focus is FOCUS_DOWN If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusForward setNextFocusForwardId(int) Defines the next view to give focus to when the next focus is FOCUS_FORWARD If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusLeft setNextFocusLeftId(int) Defines the next view to give focus to when the next focus is FOCUS_LEFT
android:nextFocusRight setNextFocusRightId(int) Defines the next view to give focus to when the next focus is FOCUS_RIGHT If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusUp setNextFocusUpId(int) Defines the next view to give focus to when the next focus is FOCUS_UP If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:onClick Name of the method in this View's context to invoke when the view is clicked. 
android:padding setPadding(int,int,int,int) Sets the padding, in pixels, of all four edges. 
android:paddingBottom setPadding(int,int,int,int) Sets the padding, in pixels, of the bottom edge; see padding
android:paddingLeft setPadding(int,int,int,int) Sets the padding, in pixels, of the left edge; see padding
android:paddingRight setPadding(int,int,int,int) Sets the padding, in pixels, of the right edge; see padding
android:paddingTop setPadding(int,int,int,int) Sets the padding, in pixels, of the top edge; see padding
android:rotation setRotation(float) rotation of the view, in degrees. 
android:rotationX setRotationX(float) rotation of the view around the x axis, in degrees. 
android:rotationY setRotationY(float) rotation of the view around the y axis, in degrees. 
android:saveEnabled setSaveEnabled(boolean) If unset, no state will be saved for this view when it is being frozen. 
android:scaleX setScaleX(float) scale of the view in the x direction. 
android:scaleY setScaleY(float) scale of the view in the y direction. 
android:scrollX The initial horizontal scroll offset, in pixels. 
android:scrollY The initial vertical scroll offset, in pixels. 
android:scrollbarAlwaysDrawHorizontalTrack Defines whether the horizontal scrollbar track should always be drawn. 
android:scrollbarAlwaysDrawVerticalTrack Defines whether the vertical scrollbar track should always be drawn. 
android:scrollbarDefaultDelayBeforeFade Defines the delay in milliseconds that a scrollbar waits before fade out. 
android:scrollbarFadeDuration Defines the delay in milliseconds that a scrollbar takes to fade out. 
android:scrollbarSize Sets the width of vertical scrollbars and height of horizontal scrollbars. 
android:scrollbarStyle Controls the scrollbar style and position. 
android:scrollbarThumbHorizontal Defines the horizontal scrollbar thumb drawable. 
android:scrollbarThumbVertical Defines the vertical scrollbar thumb drawable. 
android:scrollbarTrackHorizontal Defines the horizontal scrollbar track drawable. 
android:scrollbarTrackVertical Defines the vertical scrollbar track drawable. 
android:scrollbars Defines which scrollbars should be displayed on scrolling or not. 
android:soundEffectsEnabled setSoundEffectsEnabled(boolean) Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching. 
android:tag Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for with View.findViewWithTag()
android:transformPivotX setPivotX(float) x location of the pivot point around which the view will rotate and scale. 
android:transformPivotY setPivotY(float) y location of the pivot point around which the view will rotate and scale. 
android:translationX setTranslationX(float) translation in x of the view. 
android:translationY setTranslationY(float) translation in y of the view. 
android:visibility setVisibility(int) Controls the initial visibility of the view. 
Constants
int DRAWING_CACHE_QUALITY_AUTO

Enables automatic quality mode for the drawing cache.

int DRAWING_CACHE_QUALITY_HIGH

Enables high quality mode for the drawing cache.

int DRAWING_CACHE_QUALITY_LOW

Enables low quality mode for the drawing cache.

int FOCUSABLES_ALL View flag indicating whether addFocusables(ArrayList, int, int) should add all focusable Views regardless if they are focusable in touch mode.
int FOCUSABLES_TOUCH_MODE View flag indicating whether addFocusables(ArrayList, int, int) should add only Views focusable in touch mode.
int FOCUS_BACKWARD Use with focusSearch(int).
int FOCUS_DOWN Use with focusSearch(int).
int FOCUS_FORWARD Use with focusSearch(int).
int FOCUS_LEFT Use with focusSearch(int).
int FOCUS_RIGHT Use with focusSearch(int).
int FOCUS_UP Use with focusSearch(int).
int GONE This view is invisible, and it doesn't take any space for layout purposes.
int HAPTIC_FEEDBACK_ENABLED View flag indicating whether this view should have haptic feedback enabled for events such as long presses.
int INVISIBLE This view is invisible, but it still takes up space for layout purposes.
int KEEP_SCREEN_ON View flag indicating that the screen should remain on while the window containing this view is visible to the user.
int LAYER_TYPE_HARDWARE

Indicates that the view has a hardware layer.

int LAYER_TYPE_NONE Indicates that the view does not have a layer.
int LAYER_TYPE_SOFTWARE

Indicates that the view has a software layer.

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).
int MEASURED_SIZE_MASK Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the actual measured size.
int MEASURED_STATE_MASK Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the additional state bits.
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.
int NO_ID Used to mark a View that has no ID.
int OVER_SCROLL_ALWAYS Always allow a user to over-scroll this view, provided it is a view that can scroll.
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.
int OVER_SCROLL_NEVER Never allow a user to over-scroll this view.
int SCROLLBARS_INSIDE_INSET The scrollbar style to display the scrollbars inside the padded area, increasing the padding of the view.
int SCROLLBARS_INSIDE_OVERLAY The scrollbar style to display the scrollbars inside the content area, without increasing the padding.
int SCROLLBARS_OUTSIDE_INSET The scrollbar style to display the scrollbars at the edge of the view, increasing the padding of the view.
int SCROLLBARS_OUTSIDE_OVERLAY The scrollbar style to display the scrollbars at the edge of the view, without increasing the padding.
int SCROLLBAR_POSITION_DEFAULT Position the scroll bar at the default position as determined by the system.
int SCROLLBAR_POSITION_LEFT Position the scroll bar along the left edge.
int SCROLLBAR_POSITION_RIGHT Position the scroll bar along the right edge.
int SOUND_EFFECTS_ENABLED View flag indicating whether this view should have sound effects enabled for events such as clicking and touching.
int STATUS_BAR_HIDDEN View has requested the status bar to be hidden.
int STATUS_BAR_VISIBLE View has requested the status bar to be visible (the default).
String VIEW_LOG_TAG The logging tag used by this class with android.util.Log.
int VISIBLE This view is visible.
Fields
protected static final int[] EMPTY_STATE_SET Indicates the view has no states set.
protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET Indicates the view is enabled, focused and selected.
protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is enabled, focused, selected and its window has the focus.
protected static final int[] ENABLED_FOCUSED_STATE_SET Indicates the view is enabled and has the focus.
protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET Indicates the view is enabled, focused and its window has the focus.
protected static final int[] ENABLED_SELECTED_STATE_SET Indicates the view is enabled and selected.
protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is enabled, selected and its window has the focus.
protected static final int[] ENABLED_STATE_SET Indicates the view is enabled.
protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET Indicates the view is enabled and that its window has focus.
protected static final int[] FOCUSED_SELECTED_STATE_SET Indicates the view is focused and selected.
protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is focused, selected and its window has the focus.
protected static final int[] FOCUSED_STATE_SET Indicates the view is focused.
protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET Indicates the view has the focus and that its window has the focus.
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET Indicates the view is pressed, enabled, focused and selected.
protected static final 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 final int[] PRESSED_ENABLED_FOCUSED_STATE_SET Indicates the view is pressed, enabled and focused.
protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, enabled, focused and its window has the focus.
protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET Indicates the view is pressed, enabled and selected.
protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, enabled, selected and its window has the focus.
protected static final int[] PRESSED_ENABLED_STATE_SET Indicates the view is pressed and enabled.
protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, enabled and its window has the focus.
protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET Indicates the view is pressed, focused and selected.
protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, focused, selected and its window has the focus.
protected static final int[] PRESSED_FOCUSED_STATE_SET Indicates the view is pressed and focused.
protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, focused and its window has the focus.
protected static final int[] PRESSED_SELECTED_STATE_SET Indicates the view is pressed and selected.
protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed, selected and its window has the focus.
protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET Indicates the view is pressed and its window has the focus.
protected static final int[] SELECTED_STATE_SET Indicates the view is selected.
protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET Indicates the view is selected and that its window has the focus.
protected static final int[] WINDOW_FOCUSED_STATE_SET Indicates the view's window has focus.
Public Constructors
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.
Public Methods
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 bringToFront()
Change the view's z order in the tree, so it's on top of other sibling views
void buildDrawingCache(boolean autoScale)

Forces the drawing cache to be built if the drawing cache is invalid.

void buildDrawingCache()

Calling this method is equivalent to calling buildDrawingCache(false).

void buildLayer()
Forces this view's layer to be created and this view to be rendered into its layer.
void cancelLongPress()
Cancels a pending long press.
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 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().
void computeScroll()
Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.
void createContextMenu( ContextMenu menu)
Show the context menu for this view.
void destroyDrawingCache()

Frees the resources used by the drawing cache.

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.
boolean dispatchGenericMotionEvent( MotionEvent event)
Dispatch a generic motion 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 dispatchPopulateAccessibilityEvent( AccessibilityEvent event)
Dispatches an AccessibilityEvent to the View children to be populated.
void dispatchSystemUiVisibilityChanged(int visibility)
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.
void dispatchWindowFocusChanged(boolean hasFocus)
Called when the window containing this view gains or loses window focus.
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.
View findFocus()
Find the view in the hierarchy rooted at this view that currently has focus.
final View findViewById(int id)
Look for a child view with the given id.
final View findViewWithTag( Object tag)
Look for a child view with the given tag.
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.
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.

final int getBottom()
Bottom position of this view relative to its parent.
CharSequence getContentDescription()
Gets the View description.
final Context getContext()
Returns the context the view is running in, through which it can access the current theme, resources, etc.
static int getDefaultSize(int size, int measureSpec)
Utility to return a default size.
final int[] getDrawableState()
Return an array of resource IDs of the drawable states representing the current state of the view.
Bitmap getDrawingCache(boolean autoScale)

Returns the bitmap in which this view drawing is cached.

Bitmap getDrawingCache()

Calling this method is equivalent to calling getDrawingCache(false).

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.

boolean getFilterTouchesWhenObscured()
Gets whether the framework should discard touches when the view's window is obscured by another visible window.
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, 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.
final boolean getGlobalVisibleRect( Rect r)
Handler getHandler()
final 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.
int getId()
Returns this view's identifier.
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 getLayerType()
Indicates what type of layer is currently associated with this view.
ViewGroup.LayoutParams getLayoutParams()
Get the LayoutParams associated with this view.
final int getLeft()
Left position of this view relative to its parent.
final 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.
final int getMeasuredHeight()
Like getMeasuredHeightAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).
final int getMeasuredHeightAndState()
Return the full height measurement information for this view as computed by the most recent call to measure(int, int).
final int getMeasuredState()
Return only the state bits of getMeasuredWidthAndState() and getMeasuredHeightAndState(), combined into one integer.
final int getMeasuredWidth()
Like getMeasuredWidthAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).
final int getMeasuredWidthAndState()
Return the full width measurement information for this view as computed by the most recent call to measure(int, int).
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.
int getOverScrollMode()
Returns the over-scroll mode for this view.
int getPaddingBottom()
Returns the bottom padding of this view.
int getPaddingLeft()
Returns the left padding of this view.
int getPaddingRight()
Returns the right padding of this view.
int getPaddingTop()
Returns the top padding of this view.
final ViewParent getParent()
Gets the parent of this view.
float getPivotX()
The x location of the point around which the view is rotated and scaled.
float getPivotY()
The y location of the point around which the view is rotated and scaled.
Resources getResources()
Returns the resources associated with this view.
final int getRight()
Right position of this view relative to its parent.
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 getScrollBarStyle()

Returns the current scrollbar style.

final int getScrollX()
Return the scrolled left position of this view.
final 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.
int getSystemUiVisibility()
Returns the status bar visibility that this view has requested.
Object getTag(int key)
Returns the tag associated with this view and the specified key.
Object getTag()
Returns this view's tag.
final int getTop()
Top position of this view relative to its parent.
TouchDelegate getTouchDelegate()
Gets the TouchDelegate for this View.
ArrayList< View> getTouchables()
Find and return all touchable views that are descendants of this view, possibly including this view if it is touchable itself.
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.
ViewTreeObserver getViewTreeObserver()
Returns the ViewTreeObserver for this view's hierarchy.
int getVisibility()
Returns the visibility status for this view.
final int getWidth()
Return the width of the your view.
IBinder getWindowToken()
Retrieve a unique token identifying the window this view is attached to.
int getWindowVisibility()
Returns the current visibility of the window this view is attached to (either GONE, INVISIBLE, or VISIBLE).
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.
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.
boolean hasWindowFocus()
Returns true if this view is in a window that currently has window focus.
static View inflate( Context context, int resource, ViewGroup root)
Inflate a view from an XML resource.
void invalidate( Rect dirty)
Mark the the area defined by dirty as needing to be drawn.
void invalidate(int l, int t, int r, int b)
Mark the the area defined by the rect (l,t,r,b) as needing to be drawn.
void invalidate()
Invalidate the whole view.
void invalidateDrawable( Drawable drawable)
Invalidates the specified Drawable.
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.
final boolean isFocusable()
Returns whether this View is able to take focus.
final 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 an 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 isInEditMode()
Indicates whether this View is currently in edit mode.
boolean isInTouchMode()
Returns whether the device is currently in touch mode.
boolean isLayoutRequested()

Indicates whether or not this view's layout will be requested during the next hierarchy layout pass.

boolean isLongClickable()
Indicates whether this view reacts to long click events or not.
boolean isOpaque()
Indicates whether this View is opaque.
boolean isPressed()
Indicates whether the view is currently in pressed state.
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 isSelected()
Indicates the selection state of this view.
boolean isShown()
Returns the visibility of this view and all of its ancestors
boolean isSoundEffectsEnabled()
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.

void jumpDrawablesToCurrentState()
Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
void layout(int l, int t, int r, int b)
Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism.

final void measure(int widthMeasureSpec, int heightMeasureSpec)

This is called to find out how big a view should be.

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.
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.
InputConnection onCreateInputConnection( EditorInfo outAttrs)
Create a new InputConnection for an InputMethod to interact with the view.
boolean onDragEvent( DragEvent event)
Handles drag events sent by the system following a call to startDrag().
boolean onFilterTouchEventForSecurity( MotionEvent event)
Filter the touch event to apply security policies.
void onFinishTemporaryDetach()
Called after onStartTemporaryDetach() when the container is done changing the view.
boolean onGenericMotionEvent( MotionEvent event)
Implement this method to handle generic motion events.
boolean onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or 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 KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.
void onStartTemporaryDetach()
This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent.
boolean onTouchEvent( MotionEvent event)
Implement this method to handle touch screen motion events.
boolean onTrackballEvent( MotionEvent event)
Implement this method to handle trackball motion events.
void onWindowFocusChanged(boolean hasWindowFocus)
Called when the window containing this view gains or loses focus.
boolean performClick()
Call this view's OnClickListener, if it is defined.
boolean performHapticFeedback(int feedbackConstant, int flags)
BZZZTT!!1!

Like performHapticFeedback(int), with additional options.

boolean performHapticFeedback(int feedbackConstant)
BZZZTT!!1!

Provide haptic feedback to the user for this view.

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(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 postInvalidate()
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 postInvalidateDelayed(long delayMilliseconds)
Cause an invalidate to happen on a subsequent cycle through the event loop.
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 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.
final 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.
final boolean requestFocus()
Call this to try to give focus to a specific view or to one of its descendants.
final 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.
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.
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)
Handles the request for sending an AccessibilityEvent given the event type.
void sendAccessibilityEventUnchecked( AccessibilityEvent event)
Handles the request for sending an AccessibilityEvent.
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 setBackgroundColor(int color)
Sets the background color for this view.
void setBackgroundDrawable( Drawable d)
Set the background to a given Drawable, or remove the background.
void setBackgroundResource(int resid)
Set the background to a given resource.
final 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 setDrawingCacheBackgroundColor(int color)
Setting a solid background color for the drawing cache's bitmaps will improve perfromance 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 setFocusable(boolean focusable)
Set whether this view can receive the focus.
void setFocusableInTouchMode(boolean focusableInTouchMode)
Set whether this view can receive focus while in touch mode.
void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
Set whether this view should have haptic feedback for events such as long presses.
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 setId(int id)
Sets the identifier for this view.
void setKeepScreenOn(boolean keepScreenOn)
Controls whether the screen should remain on, modifying the value of KEEP_SCREEN_ON.
void setLayerType(int layerType, Paint paint)

Specifies the type of layer backing this view.

void setLayoutParams( ViewGroup.LayoutParams params)
Set the layout parameters associated with this view.
final 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.
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 setOnKeyListener( View.OnKeyListener l)
Register a callback to be invoked when a 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 setPivotX(float pivotX)
Sets the x location of the point around which the view is rotated and scaled.
void setPivotY(float pivotY)
Sets the y location of the point around which the view is rotated and scaled.
void setPressed(boolean pressed)
Sets the pressed state for this view.
final 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 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 setScrollbarFadingEnabled(boolean fadeScrollbars)
Define whether scrollbars will fade when the view is not scrolling.
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 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.
final 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.
ActionMode startActionMode( ActionMode.Callback callback)
Start an action mode.
void startAnimation( Animation animation)
Start the specified animation now.
final boolean startDrag( ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)
Starts a drag and drop operation.
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.
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 Methods
boolean awakenScrollBars(int startDelay)

Trigger the scrollbars to draw.

boolean awakenScrollBars(int startDelay, boolean invalidate)

Trigger the scrollbars to draw.

boolean awakenScrollBars()

Trigger the scrollbars to draw.

int computeHorizontalScrollExtent()

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollOffset()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

int computeVerticalScrollExtent()

Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range.

int computeVerticalScrollOffset()

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range.

int computeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

void dispatchDraw( Canvas canvas)
Called by draw to draw the child views.
void dispatchRestoreInstanceState( SparseArray< Parcelable> container)
Called by restoreHierarchyState(SparseArray ) to retrieve the state for this view and its children.
void dispatchSaveInstanceState( SparseArray< Parcelable> container)
Called by saveHierarchyState(SparseArray ) to store the state for this view and its children.
void dispatchSetActivated(boolean activated)
Dispatch setActivated to all of this View's children.
void dispatchSetPressed(boolean pressed)
Dispatch setPressed to all of this View's children.
void dispatchSetSelected(boolean selected)
Dispatch setSelected to all of this View's children.
void dispatchVisibilityChanged( View changedView, int visibility)
Dispatch a view visibility change down the view hierarchy.
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.
boolean fitSystemWindows( Rect insets)
Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag is set
float getBottomFadingEdgeStrength()
Returns the strength, or intensity, of the bottom faded edge.
int getBottomPaddingOffset()
Amount by which to extend the bottom fading region.
ContextMenu.ContextMenuInfo getContextMenuInfo()
Views should implement this if they have extra information to associate with the context menu.
int getHorizontalScrollbarHeight()
Returns the height of the horizontal scrollbar.
float getLeftFadingEdgeStrength()
Returns the strength, or intensity, of the left faded edge.
int getLeftPaddingOffset()
Amount by which to extend the left fading region.
float getRightFadingEdgeStrength()
Returns the strength, or intensity, of the right faded edge.
int getRightPaddingOffset()
Amount by which to extend the right fading region.
int getSuggestedMinimumHeight()
Returns the suggested minimum height that the view should use.
int getSuggestedMinimumWidth()
Returns the suggested minimum width that the view should use.
float getTopFadingEdgeStrength()
Returns the strength, or intensity, of the top faded edge.
int getTopPaddingOffset()
Amount by which to extend the top fading region.
int getWindowAttachCount()
void initializeFadingEdge( TypedArray a)

Initializes the fading edges from a given set of styled attributes.

void initializeScrollbars( TypedArray a)

Initializes the scrollbars from a given set of styled attributes.

boolean isPaddingOffsetRequired()
If the View draws content inside its padding and enables fading edges, it needs to support padding offsets.
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 onAnimationEnd()
Invoked by a parent ViewGroup to notify the end of the animation currently associated with this view.
void onAnimationStart()
Invoked by a parent ViewGroup to notify the start of the animation currently associated with this view.
void onAttachedToWindow()
This is called when the view is attached to a window.
void onConfigurationChanged( Configuration newConfig)
Called when the current configuration of the resources being used by the application have changed.
void onCreateContextMenu( ContextMenu menu)
Views should implement this if the view itself is going to add items to the context menu.
int[] onCreateDrawableState(int extraSpace)
Generate the new Drawable state for this view.
void onDetachedFromWindow()
This is called when the view is detached from a window.
void onDisplayHint(int hint)
Gives this view a hint about whether is displayed or not.
void onDraw( Canvas canvas)
Implement this to do your drawing.
final void onDrawScrollBars( Canvas canvas)

Request the drawing of the horizontal and the vertical scrollbar.

void onFinishInflate()
Finalize inflating a view from XML.
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
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.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

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 onRestoreInstanceState( Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().
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 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).
boolean onSetAlpha(int alpha)
Invoked if there is a Transform that involves alpha.
void onSizeChanged(int w, int h, int oldw, int oldh)
This is called during layout when the size of this view has changed.
void onVisibilityChanged( View changedView, int visibility)
Called when the visibility of the view or an ancestor of the view is changed.
void onWindowVisibilityChanged(int visibility)
Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE).
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.
final void setMeasuredDimension(int measuredWidth, int measuredHeight)

This mehod must be called by onMeasure(int, int) to store the measured width and measured height.

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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android:alpha

Since: API Level

alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque).

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol alpha.

Related Methods

android:background

Since: API Level

A drawable to use as the background. This can be either a reference to a full drawable resource (such as a PNG image, 9-patch, XML state list description, etc), or a solid color such as "#ff000000" (black).

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol background.

Related Methods

android:clickable

Since: API Level

Defines whether this view reacts to click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol clickable.

Related Methods

android:contentDescription

Since: API Level

Defines text that briefly describes content of the view. This property is used primarily for accessibility. Since some views do not have textual representation this attribute can be used for providing such.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol contentDescription.

android:drawingCacheQuality

Since: API Level

Defines the quality of translucent drawing caches. This property is used only when the drawing cache is enabled and translucent. The default value is auto.

Must be one of the following constant values.

Constant Value Description
auto Lets the framework decide what quality level should be used for the drawing cache.
low 1 Low quality. When set to low quality, the drawing cache uses a lower color depth, thus losing precision in rendering gradients, but uses less memory.
high 2 High quality. When set to high quality, the drawing cache uses a higher color depth but uses more memory.

This corresponds to the global attribute resource symbol drawingCacheQuality.

Related Methods

android:duplicateParentState

Since: API Level

When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol duplicateParentState.

Related Methods

android:fadingEdge

Since: API Level

Defines which edges should be fadeded on scrolling.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
none 0x00000000 No edge is faded.
horizontal 0x00001000 Fades horizontal edges only.
vertical 0x00002000 Fades vertical edges only.

This corresponds to the global attribute resource symbol fadingEdge.

android:fadingEdgeLength

Since: API Level

Defines the length of the fading edges.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fadingEdgeLength.

android:filterTouchesWhenObscured

Since: API Level

Specifies whether to filter touches when the view's window is obscured by another visible window. When set to true, the view will not receive touches whenever a toast, dialog or other window appears above the view's window. Refer to the View security documentation for more details.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol filterTouchesWhenObscured.

android:fitsSystemWindows

Since: API Level

Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fitsSystemWindows.

Related Methods

android:focusable

Since: API Level

Boolean that controls whether a view can take focus. By default the user can not move focus to a view; by setting this attribute to true the view is allowed to take focus. This value does not impact the behavior of directly calling requestFocus(), which will always request focus regardless of this view. It only impacts where focus navigation will try to move focus.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol focusable.

Related Methods

android:focusableInTouchMode

Since: API Level

Boolean that controls whether a view can take focus while in touch mode. If this is true for a view, that view can gain focus when clicked on, and can keep focus if another view is clicked on that doesn't have this attribute set to true.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol focusableInTouchMode.

android:hapticFeedbackEnabled

Since: API Level

Boolean that controls whether a view should have haptic feedback enabled for events such as long presses.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol hapticFeedbackEnabled.

android:id

Since: API Level

Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById(). This must be a resource reference; typically you set this using the @+ syntax to create a new ID resources. For example: android:id="@+id/my_id" which allows you to later retrieve the view with findViewById(R.id.my_id).

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol id.

Related Methods

android:isScrollContainer

Since: API Level

Set this if the view will serve as a scrolling container, meaing that it can be resized to shrink its overall window so that there will be space for an input method. If not set, the default value will be true if "scrollbars" has the vertical scrollbar set, else it will be false.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol isScrollContainer.

Related Methods

android:keepScreenOn

Since: API Level

Controls whether the view's window should keep the screen on while visible.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol keepScreenOn.

Related Methods

android:layerType

Since: API Level

Specifies the type of layer backing this view. The default value is none. Refer to setLayerType(int, android.graphics.Paint) for more information.

Must be one of the following constant values.

Constant Value Description
none Don't use a layer.
software 1 Use a software layer. Refer to for more information.
hardware 2 Use a hardware layer. Refer to {@link android.view.View#setLayerType(int, android.graphics.Paint) for more information.

This corresponds to the global attribute resource symbol {@link android.R.attr#layerType.

Related Methods

android:longClickable

Since: API Level

Defines whether this view reacts to long click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol longClickable.

Related Methods

android:minHeight

Since: API Level

Defines the minimum height of the view. It is not guaranteed the view will be able to achieve this minimum height (for example, if its parent layout constrains it with less available height).

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minHeight.

Related Methods

android:minWidth

Since: API Level

Defines the minimum width of the view. It is not guaranteed the view will be able to achieve this minimum width (for example, if its parent layout constrains it with less available width).

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minWidth.

Related Methods

android:nextFocusDown

Since: API Level

Defines the next view to give focus to when the next focus is FOCUS_DOWN If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol nextFocusDown.

Related Methods

android:nextFocusForward

Since: API Level

Defines the next view to give focus to when the next focus is FOCUS_FORWARD If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol nextFocusForward.

Related Methods

android:nextFocusLeft

Since: API Level

Defines the next view to give focus to when the next focus is FOCUS_LEFT. If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol nextFocusLeft.

Related Methods

android:nextFocusRight

Since: API Level

Defines the next view to give focus to when the next focus is FOCUS_RIGHT If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol nextFocusRight.

Related Methods

android:nextFocusUp

Since: API Level

Defines the next view to give focus to when the next focus is FOCUS_UP If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol nextFocusUp.

Related Methods

android:onClick

Since: API Level

Name of the method in this View's context to invoke when the view is clicked. This name must correspond to a public method that takes exactly one parameter of type View. For instance, if you specify android:onClick="sayHello", you must declare a public void sayHello(View v) method of your context (typically, your Activity).

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol onClick.

Related Methods

android:padding

Since: API Level

Sets the padding, in pixels, of all four edges. Padding is defined as space between the edges of the view and the view's content. A views size will include it's padding. If a background is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol padding.

Related Methods

android:paddingBottom

Since: API Level

Sets the padding, in pixels, of the bottom edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingBottom.

Related Methods

android:paddingLeft

Since: API Level

Sets the padding, in pixels, of the left edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingLeft.

Related Methods

android:paddingRight

Since: API Level

Sets the padding, in pixels, of the right edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingRight.

Related Methods

android:paddingTop

Since: API Level

Sets the padding, in pixels, of the top edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingTop.

Related Methods

android:rotation

Since: API Level

rotation of the view, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotation.

Related Methods

android:rotationX

Since: API Level

rotation of the view around the x axis, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotationX.

Related Methods

android:rotationY

Since: API Level

rotation of the view around the y axis, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotationY.

Related Methods

android:saveEnabled

Since: API Level

If unset, no state will be saved for this view when it is being frozen. The default is true, allowing the view to be saved (however it also must have an ID assigned to it for its state to be saved). Setting this to false only disables the state for this view, not for its children which may still be saved.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol saveEnabled.

Related Methods

android:scaleX

Since: API Level

scale of the view in the x direction.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scaleX.

Related Methods

android:scaleY

Since: API Level

scale of the view in the y direction.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scaleY.

Related Methods

android:scrollX

Since: API Level

The initial horizontal scroll offset, in pixels.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollX.

Related Methods

android:scrollY

Since: API Level

The initial vertical scroll offset, in pixels.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollY.

Related Methods

android:scrollbarAlwaysDrawHorizontalTrack

Since: API Level

Defines whether the horizontal scrollbar track should always be drawn.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarAlwaysDrawHorizontalTrack.

Related Methods

android:scrollbarAlwaysDrawVerticalTrack

Since: API Level

Defines whether the vertical scrollbar track should always be drawn.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarAlwaysDrawVerticalTrack.

Related Methods

android:scrollbarDefaultDelayBeforeFade

Since: API Level

Defines the delay in milliseconds that a scrollbar waits before fade out.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarDefaultDelayBeforeFade.

Related Methods

android:scrollbarFadeDuration

Since: API Level

Defines the delay in milliseconds that a scrollbar takes to fade out.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarFadeDuration.

Related Methods

android:scrollbarSize

Since: API Level

Sets the width of vertical scrollbars and height of horizontal scrollbars.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarSize.

Related Methods

android:scrollbarStyle

Since: API Level

Controls the scrollbar style and position. 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 insideOverlay or insideInset. If you want them to appear at the edge of the view, ignoring the padding, then you can use outsideOverlay or outsideInset.

Must be one of the following constant values.

Constant Value Description
insideOverlay 0x0 Inside the padding and overlaid
insideInset 0x01000000 Inside the padding and inset
outsideOverlay 0x02000000 Edge of the view and overlaid
outsideInset 0x03000000 Edge of the view and inset

This corresponds to the global attribute resource symbol scrollbarStyle.

Related Methods

android:scrollbarThumbHorizontal

Since: API Level

Defines the horizontal scrollbar thumb drawable.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol scrollbarThumbHorizontal.

Related Methods

android:scrollbarThumbVertical

Since: API Level

Defines the vertical scrollbar thumb drawable.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol scrollbarThumbVertical.

Related Methods

android:scrollbarTrackHorizontal

Since: API Level

Defines the horizontal scrollbar track drawable.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol scrollbarTrackHorizontal.

Related Methods

android:scrollbarTrackVertical

Since: API Level

Defines the vertical scrollbar track drawable.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol scrollbarTrackVertical.

Related Methods

android:scrollbars

Since: API Level

Defines which scrollbars should be displayed on scrolling or not.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
none 0x00000000 No scrollbar is displayed.
horizontal 0x00000100 Displays horizontal scrollbar only.
vertical 0x00000200 Displays vertical scrollbar only.

This corresponds to the global attribute resource symbol scrollbars.

Related Methods

android:soundEffectsEnabled

Since: API Level

Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol soundEffectsEnabled.

android:tag

Since: API Level

Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for with View.findViewWithTag(). It is generally preferable to use IDs (through the android:id attribute) instead of tags because they are faster and allow for compile-time type checking.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol tag.

Related Methods

android:transformPivotX

Since: API Level

x location of the pivot point around which the view will rotate and scale. This xml attribute sets the pivotX property of the View.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol transformPivotX.

Related Methods

android:transformPivotY

Since: API Level

y location of the pivot point around which the view will rotate and scale. This xml attribute sets the pivotY property of the View.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol transformPivotY.

Related Methods

android:translationX

Since: API Level

translation in x of the view. This value is added post-layout to the left property of the view, which is set by its layout.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol translationX.

Related Methods

android:translationY

Since: API Level

translation in y of the view. This value is added post-layout to the left property of the view, which is set by its layout.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol translationY.

Related Methods

android:visibility

Since: API Level

Controls the initial visibility of the view.

Must be one of the following constant values.

Constant Value Description
visible Visible on screen; the default value.
invisible 1 Not displayed, but taken into account during layout (space is left for it).
gone 2 Completely hidden, as if the view had not been added.

This corresponds to the global attribute resource symbol visibility.

Related Methods

Constants

public static final int DRAWING_CACHE_QUALITY_AUTO

Since: API Level 1

Enables automatic quality mode for the drawing cache.

Constant Value: 0 (0x00000000)

public static final int DRAWING_CACHE_QUALITY_HIGH

Since: API Level 1

Enables high quality mode for the drawing cache.

Constant Value: 1048576 (0x00100000)

public static final int DRAWING_CACHE_QUALITY_LOW

Since: API Level 1

Enables low quality mode for the drawing cache.

Constant Value: 524288 (0x00080000)

public static final int FOCUSABLES_ALL

Since: API Level 4

View flag indicating whether addFocusables(ArrayList, int, int) should add all focusable Views regardless if they are focusable in touch mode.

Constant Value: 0 (0x00000000)

public static final int FOCUSABLES_TOUCH_MODE

Since: API Level 4

View flag indicating whether addFocusables(ArrayList, int, int) should add only Views focusable in touch mode.

Constant Value: 1 (0x00000001)

public static final int FOCUS_BACKWARD

Since: API Level 1

Use with focusSearch(int). Move focus to the previous selectable item.

Constant Value: 1 (0x00000001)

public static final int FOCUS_DOWN

Since: API Level 1

Use with focusSearch(int). Move focus down.

Constant Value: 130 (0x00000082)

public static final int FOCUS_FORWARD

Since: API Level 1

Use with focusSearch(int). Move focus to the next selectable item.

Constant Value: 2 (0x00000002)

public static final int FOCUS_LEFT

Since: API Level 1

Use with focusSearch(int). Move focus to the left.

Constant Value: 17 (0x00000011)

public static final int FOCUS_RIGHT

Since: API Level 1

Use with focusSearch(int). Move focus to the right.

Constant Value: 66 (0x00000042)

public static final int FOCUS_UP

Since: API Level 1

Use with focusSearch(int). Move focus up.

Constant Value: 33 (0x00000021)

public static final int GONE

Since: API Level 1

This view is invisible, and it doesn't take any space for layout purposes. Use with setVisibility(int).

Constant Value: 8 (0x00000008)

public static final int HAPTIC_FEEDBACK_ENABLED

Since: API Level 3

View flag indicating whether this view should have haptic feedback enabled for events such as long presses.

Constant Value: 268435456 (0x10000000)

public static final int INVISIBLE

Since: API Level 1

This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int).

Constant Value: 4 (0x00000004)

public static final int KEEP_SCREEN_ON

Since: API Level 1

View flag indicating that the screen should remain on while the window containing this view is visible to the user. This effectively takes care of automatically setting the WindowManager's FLAG_KEEP_SCREEN_ON.

Constant Value: 67108864 (0x04000000)

public static final int LAYER_TYPE_HARDWARE

Since: API Level 11

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.

Constant Value: 2 (0x00000002)

public static final int LAYER_TYPE_NONE

Since: API Level 11

Indicates that the view does not have a layer.

Constant Value: 0 (0x00000000)

public static final int LAYER_TYPE_SOFTWARE

Since: API Level 11

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.)

Constant Value: 1 (0x00000001)

public static final int MEASURED_HEIGHT_STATE_SHIFT

Since: API Level 11

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).

Constant Value: 16 (0x00000010)

public static final int MEASURED_SIZE_MASK

Since: API Level 11

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the actual measured size.

Constant Value: 16777215 (0x00ffffff)

public static final int MEASURED_STATE_MASK

Since: API Level 11

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the additional state bits.

Constant Value: -16777216 (0xff000000)

public static final int MEASURED_STATE_TOO_SMALL

Since: API Level 11

Bit of getMeasuredWidthAndState() and getMeasuredWidthAndState() that indicates the measured size is smaller that the space the view would like to have.

Constant Value: 16777216 (0x01000000)

public static final int NO_ID

Since: API Level 1

Used to mark a View that has no ID.

Constant Value: -1 (0xffffffff)

public static final int OVER_SCROLL_ALWAYS

Since: API Level 9

Always allow a user to over-scroll this view, provided it is a view that can scroll.

Constant Value: 0 (0x00000000)

public static final int OVER_SCROLL_IF_CONTENT_SCROLLS

Since: API Level 9

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.

Constant Value: 1 (0x00000001)

public static final int OVER_SCROLL_NEVER

Since: API Level 9

Never allow a user to over-scroll this view.

Constant Value: 2 (0x00000002)

public static final int SCROLLBARS_INSIDE_INSET

Since: API Level 1

The scrollbar style to display the scrollbars inside the padded area, increasing the padding of the view. The scrollbars will not overlap the content area of the view.

Constant Value: 16777216 (0x01000000)

public static final int SCROLLBARS_INSIDE_OVERLAY

Since: API Level 1

The scrollbar style to display the scrollbars inside the content area, without increasing the padding. The scrollbars will be overlaid with translucency on the view's content.

Constant Value: 0 (0x00000000)

public static final int SCROLLBARS_OUTSIDE_INSET

Since: API Level 1

The scrollbar style to display the scrollbars at the edge of the view, increasing the padding of the view. The scrollbars will only overlap the background, if any.

Constant Value: 50331648 (0x03000000)

public static final int SCROLLBARS_OUTSIDE_OVERLAY

Since: API Level 1

The scrollbar style to display the scrollbars at the edge of the view, without increasing the padding. The scrollbars will be overlaid with translucency.

Constant Value: 33554432 (0x02000000)

public static final int SCROLLBAR_POSITION_DEFAULT

Since: API Level 11

Position the scroll bar at the default position as determined by the system.

Constant Value: 0 (0x00000000)

public static final int SCROLLBAR_POSITION_LEFT

Since: API Level 11

Position the scroll bar along the left edge.

Constant Value: 1 (0x00000001)

public static final int SCROLLBAR_POSITION_RIGHT

Since: API Level 11

Position the scroll bar along the right edge.

Constant Value: 2 (0x00000002)

public static final int SOUND_EFFECTS_ENABLED

Since: API Level 1

View flag indicating whether this view should have sound effects enabled for events such as clicking and touching.

Constant Value: 134217728 (0x08000000)

public static final int STATUS_BAR_HIDDEN

Since: API Level 11

View has requested the status bar to be hidden.

Constant Value: 1 (0x00000001)

public static final int STATUS_BAR_VISIBLE

Since: API Level 11

View has requested the status bar to be visible (the default).

Constant Value: 0 (0x00000000)

protected static final String VIEW_LOG_TAG

Since: API Level 1

The logging tag used by this class with android.util.Log.

Constant Value: "View"

public static final int VISIBLE

Since: API Level 1

This view is visible. Use with setVisibility(int).

Constant Value: 0 (0x00000000)

Fields

protected static final int[] EMPTY_STATE_SET

Since: API Level 1

Indicates the view has no states set. States are used with Drawable to change the drawing of the view depending on its state.

protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is enabled, focused and selected.

protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is enabled, focused, selected and its window has the focus.

protected static final int[] ENABLED_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is enabled and has the focus.

protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is enabled, focused and its window has the focus.

protected static final int[] ENABLED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is enabled and selected.

protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is enabled, selected and its window has the focus.

protected static final int[] ENABLED_STATE_SET

Since: API Level 1

Indicates the view is enabled. States are used with Drawable to change the drawing of the view depending on its state.

protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is enabled and that its window has focus.

protected static final int[] FOCUSED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is focused and selected.

protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is focused, selected and its window has the focus.

protected static final int[] FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is focused. States are used with Drawable to change the drawing of the view depending on its state.

protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view has the focus and that its window has the focus.

protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled, focused and selected.

protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled, focused, selected and its window has the focus.

protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled and focused.

protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled, focused and its window has the focus.

protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled and selected.

protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled, selected and its window has the focus.

protected static final int[] PRESSED_ENABLED_STATE_SET

Since: API Level 1

Indicates the view is pressed and enabled.

protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, enabled and its window has the focus.

protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is pressed, focused and selected.

protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, focused, selected and its window has the focus.

protected static final int[] PRESSED_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed and focused.

protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, focused and its window has the focus.

protected static final int[] PRESSED_SELECTED_STATE_SET

Since: API Level 1

Indicates the view is pressed and selected.

protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed, selected and its window has the focus.

protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is pressed and its window has the focus.

protected static final int[] SELECTED_STATE_SET

Since: API Level 1

Indicates the view is selected. States are used with Drawable to change the drawing of the view depending on its state.

protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view is selected and that its window has the focus.

protected static final int[] WINDOW_FOCUSED_STATE_SET

Since: API Level 1

Indicates the view's window has focus. States are used with Drawable to change the drawing of the view depending on its state.

Public Constructors

public View (Context context)

Since: API Level 1

Simple constructor to use when creating a view from code.

Parameters
context The Context the view is running in, through which it can access the current theme, resources, etc.

public View (Context context, AttributeSet attrs)

Since: API Level 1

Constructor that is called when inflating a view from XML. This is called when a view is being constructed from an XML file, supplying attributes that were specified in the XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.

The method onFinishInflate() will be called after all children have been added.

Parameters
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.

public View (Context context, AttributeSet attrs, int defStyle)

Since: API Level 1

Perform inflation from XML and apply a class-specific base style. This constructor of View allows subclasses to use their own base style when they are inflating. For example, a Button class's constructor would call this version of the super class constructor and supply 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.

Parameters
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.

Public Methods

public void addFocusables (ArrayList<View> views, int direction)

Since: API Level 1

Add any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. If we are in touch mode, only add views that are also focusable in touch mode.

Parameters
views Focusable views found so far
direction The direction of the focus

public void addFocusables (ArrayList<View> views, int direction, int focusableMode)

Since: API Level 4

Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. This method adds all focusable views regardless if we are in touch mode or only views focusable in touch mode if we are in touch mode depending on the focusable mode paramater.

Parameters
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.

public void addOnAttachStateChangeListener (View.OnAttachStateChangeListener listener)

Since: API Level 12

Add a listener for attach state changes. This listener will be called whenever this view is attached or detached from a window. Remove the listener using removeOnAttachStateChangeListener(OnAttachStateChangeListener).

Parameters
listener Listener to attach

public void addOnLayoutChangeListener (View.OnLayoutChangeListener listener)

Since: API Level 11

Add a listener that will be called when the bounds of the view change due to layout processing.

Parameters
listener The listener that will be called when layout bounds change.

public void addTouchables (ArrayList<View> views)

Since: API Level 1

Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.

Parameters
views Touchable views found so far

public ViewPropertyAnimator animate ()

Since: API Level 12

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

Returns
  • ViewPropertyAnimator The ViewPropertyAnimator associated with this View.

public void bringToFront ()

Since: API Level 1

Change the view's z order in the tree, so it's on top of other sibling views

public void buildDrawingCache (boolean autoScale)

Since: API Level 4

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.

public void buildDrawingCache ()

Since: API Level 1

Calling this method is equivalent to calling buildDrawingCache(false).

public void buildLayer ()

Since: API Level 12

Forces this view's layer to be created and this view to be rendered into its layer. If this view's layer type is set to 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.

Throws
IllegalStateException If this view is not attached to a window

public void cancelLongPress ()

Since: API Level 1

Cancels a pending long press. Your subclass can use this if you want the context menu to come up if the user presses and holds at the same place, but you don't want it to come up if they press and then move around enough to cause scrolling.

public boolean checkInputConnectionProxy (View view)

Since: API Level 3

Called by the 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.

Parameters
view The View that is making the InputMethodManager call.
Returns
  • Return true to allow the call, false to reject.

public void clearAnimation ()

Since: API Level 1

Cancels any animations for this view.

public void clearFocus ()

Since: API Level 1

Called when this view wants to give up focus. This will cause onFocusChanged(boolean, int, Rect) to be called.

public static int combineMeasuredStates (int curState, int newState)

Since: API Level 11

Merge two states as returned by getMeasuredState().

Parameters
curState The current state as returned from a view or the result of combining multiple views.
newState The new view state to combine.
Returns
  • Returns a new integer reflecting the combination of the two states.

public void computeScroll ()

Since: API Level 1

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a Scroller object.

public void createContextMenu (ContextMenu menu)

Since: API Level 1

Show the context menu for this view. It is not safe to hold on to the menu after returning from this method. You should normally not overload this method. Overload onCreateContextMenu(ContextMenu) or define an View.OnCreateContextMenuListener to add items to the context menu.

Parameters
menu The context menu to populate

public void destroyDrawingCache ()

Since: API Level 1

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 dispatchConfigurationChanged (Configuration newConfig)

Since: API Level 8

Dispatch a notification about a resource configuration change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
newConfig The new resource configuration.

public void dispatchDisplayHint (int hint)

Since: API Level 8

Dispatch a hint about whether this view is displayed. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.

Parameters
hint A hint about whether or not this view is displayed: VISIBLE or INVISIBLE.

public boolean dispatchDragEvent (DragEvent event)

Since: API Level 11

Detects if this View is enabled and has a drag event listener. If both are true, then it calls the drag event listener with the 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 boolean dispatchGenericMotionEvent (MotionEvent event)

Since: API Level 12

Dispatch a generic motion event.

Generic motion events with source class SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchKeyEvent (KeyEvent event)

Since: API Level 1

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public boolean dispatchKeyEventPreIme (KeyEvent event)

Since: API Level 3

Dispatch a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public boolean dispatchKeyShortcutEvent (KeyEvent event)

Since: API Level 1

Dispatches a key shortcut event.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Since: API Level 4

Dispatches an AccessibilityEvent to the View children to be populated.

Parameters
event The event.
Returns
  • True if the event population was completed.

public void dispatchSystemUiVisibilityChanged (int visibility)

Since: API Level 11

public boolean dispatchTouchEvent (MotionEvent event)

Since: API Level 1

Pass the touch screen motion event down to the target view, or this view if it is the target.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchTrackballEvent (MotionEvent event)

Since: API Level 1

Pass a trackball motion event down to the focused view.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchUnhandledMove (View focused, int direction)

Since: API Level 1

This method is the last chance for the focused view and its ancestors to respond to an arrow key. This is called when the focused view did not consume the key internally, nor could the view system find a new view in the requested direction to give focus to.

Parameters
focused The currently focused view.
direction The direction focus wants to move. One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT.
Returns
  • True if the this view consumed this unhandled move.

public void dispatchWindowFocusChanged (boolean hasFocus)

Since: API Level 1

Called when the window containing this view gains or loses window focus. ViewGroups should override to route to their children.

Parameters
hasFocus True if the window containing this view now has focus, false otherwise.

public void dispatchWindowVisibilityChanged (int visibility)

Since: API Level 1

Dispatch a window visibility change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
visibility The new visibility of the window.

public void draw (Canvas canvas)

Since: API Level 1

Manually render this view (and all of its children) to the given Canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.

Parameters
canvas The Canvas to which the View is rendered.

public View findFocus ()

Since: API Level 1

Find the view in the hierarchy rooted at this view that currently has focus.

Returns
  • The view that currently has focus, or null if no focused view can be found.

public final View findViewById (int id)

Since: API Level 1

Look for a child view with the given id. If this view has the given id, return this view.

Parameters
id The id to search for.
Returns
  • The view that has the given id in the hierarchy or null

public final View findViewWithTag (Object tag)

Since: API Level 1

Look for a child view with the given tag. If this view has the given tag, return this view.

Parameters
tag The tag to search for, using "tag.equals(getTag())".
Returns
  • The View that has the given tag in the hierarchy or null

public View focusSearch (int direction)

Since: API Level 1

Find the nearest view in the specified direction that can take focus. This does not actually give focus to that view.

Parameters
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
Returns
  • The nearest focusable in the specified direction, or null if none can be found.

public void forceLayout ()

Since: API Level 1

Forces this view to be laid out during the next layout pass. This method does not call requestLayout() or forceLayout() on the parent.

public float getAlpha ()

Since: API Level 11

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.

By default this is 1.0f.

Returns
  • The opacity of the view.

public Animation getAnimation ()

Since: API Level 1

Get the animation currently associated with this view.

Returns
  • The animation that is currently playing or scheduled to play for this view.

public IBinder getApplicationWindowToken ()

Since: API Level 1

Retrieve a unique token identifying the top-level "real" window of the window that this view is attached to. That is, this is like 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.

Returns
  • Returns the associated window token, either getWindowToken() or the containing window's token.

public Drawable getBackground ()

Since: API Level 1

Gets the background drawable

Returns
  • The drawable used as the background for this view, if any.

public int getBaseline ()

Since: API Level 1

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.

Returns
  • the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

public final int getBottom ()

Since: API Level 1

Bottom position of this view relative to its parent.

Returns
  • The bottom of this view, in pixels.

public CharSequence getContentDescription ()

Since: API Level 4

Gets the 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).

Related XML Attributes
Returns
  • The content descriptiopn.

public final Context getContext ()

Since: API Level 1

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Returns
  • The view's Context.

public static int getDefaultSize (int size, int measureSpec)

Since: API Level 1

Utility to return a default size. Uses the supplied size if the MeasureSpec imposed no contraints. Will get larger if allowed by the MeasureSpec.

Parameters
size Default size for this view
measureSpec Constraints imposed by the parent
Returns
  • The size this view should be.

public final int[] getDrawableState ()

Since: API Level 1

Return an array of resource IDs of the drawable states representing the current state of the view.

Returns
  • The current drawable state

public Bitmap getDrawingCache (boolean autoScale)

Since: API Level 4

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.

Parameters
autoScale Indicates whether the generated bitmap should be scaled based on the current density of the screen when the application is in compatibility mode.
Returns
  • A bitmap representing this view or null if cache is disabled.

public Bitmap getDrawingCache ()

Since: API Level 1

Calling this method is equivalent to calling getDrawingCache(false).

Returns
  • A non-scaled bitmap representing this view or null if cache is disabled.

public int getDrawingCacheBackgroundColor ()

Since: API Level 1

Returns
  • The background color to used for the drawing cache's bitmap

public int getDrawingCacheQuality ()

Since: API Level 1

public void getDrawingRect (Rect outRect)

Since: API Level 1

Return the visible drawing bounds of your view. Fills in the output rectangle with the values from getScrollX(), getScrollY(), getWidth(), and getHeight().

Parameters
outRect The (scrolled) drawing bounds of the view.

public long getDrawingTime ()

Since: API Level 1

Return the time at which the drawing of the view hierarchy started.

Returns
  • the drawing start time in milliseconds

public boolean getFilterTouchesWhenObscured ()

Since: API Level 9

Gets whether the framework should discard touches when the view's window is obscured by another visible window. Refer to the View security documentation for more details.

Related XML Attributes
Returns
  • True if touch filtering is enabled.

public ArrayList<View> getFocusables (int direction)

Since: API Level 1

Find and return all focusable views that are descendants of this view, possibly including this view if it is focusable itself.

Parameters
direction The direction of the focus
Returns
  • A list of focusable views

public void getFocusedRect (Rect r)

Since: API Level 1

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. By default, the rectange is the getDrawingRect(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.

Parameters
r The rectangle to fill in, in this view's coordinates.

public boolean getGlobalVisibleRect (Rect r, Point globalOffset)

Since: API Level 1

If some part of this view is not clipped by any of its parents, then return that area in r in global (root) coordinates. To convert r to local coordinates, offset it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)) If the view is completely clipped or translated out, return false.

Parameters
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.
Returns
  • true if r is non-empty (i.e. part of the view is visible at the root level.

public final boolean getGlobalVisibleRect (Rect r)

Since: API Level 1

public Handler getHandler ()

Since: API Level 1

Returns
  • A handler associated with the thread running the View. This handler can be used to pump events in the UI events queue.

public final int getHeight ()

Since: API Level 1

Return the height of your view.

Returns
  • The height of your view, in pixels.

public void getHitRect (Rect outRect)

Since: API Level 1

Hit rectangle in parent's coordinates

Parameters
outRect The hit rectangle of the view.

public int getHorizontalFadingEdgeLength ()

Since: API Level 1

Returns the size of the horizontal faded edges used to indicate that more content in this view is visible.

Related XML Attributes
Returns
  • The size in pixels of the horizontal faded edge or 0 if horizontal faded edges are not enabled for this view.

public int getId ()

Since: API Level 1

Returns this view's identifier.

Related XML Attributes
Returns
  • a positive integer used to identify the view or NO_ID if the view has no ID

public boolean getKeepScreenOn ()

Since: API Level 1

Returns whether the screen should remain on, corresponding to the current value of KEEP_SCREEN_ON.

Related XML Attributes
Returns

public KeyEvent.DispatcherState getKeyDispatcherState ()

Since: API Level 5

Return the global 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 int getLayerType ()

Since: API Level 11

Indicates what type of layer is currently associated with this view. By default a view does not have a layer, and the layer type is LAYER_TYPE_NONE. Refer to the documentation of setLayerType(int, android.graphics.Paint) for more information on the different types of layers.

public ViewGroup.LayoutParams getLayoutParams ()

Since: API Level 1

Get the LayoutParams associated with this view. All views should have layout parameters. These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children. This method may return null if this View is not attached to a parent ViewGroup or setLayoutParams(android.view.ViewGroup.LayoutParams) was not invoked successfully. When a View is attached to a parent ViewGroup, this method must not return null.

Returns
  • The LayoutParams associated with this view, or null if no parameters have been set yet

public final int getLeft ()

Since: API Level 1

Left position of this view relative to its parent.

Returns
  • The left edge of this view, in pixels.

public final boolean getLocalVisibleRect (Rect r)

Since: API Level 1

public void getLocationInWindow (int[] location)

Since: API Level 1

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.

Parameters
location an array of two integers in which to hold the coordinates

public void getLocationOnScreen (int[] location)

Since: API Level 1

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.

Parameters
location an array of two integers in which to hold the coordinates

public Matrix getMatrix ()

Since: API Level 11

The transform matrix of this view, which is calculated based on the current roation, scale, and pivot properties.

Returns
  • The current transform matrix for the view

public final int getMeasuredHeight ()

Since: API Level 1

Like getMeasuredHeightAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

Returns
  • The raw measured height of this view.

public final int getMeasuredHeightAndState ()

Since: API Level 11

Return the full height measurement information for this view as computed by the most recent call to 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.

Returns
  • The measured width of this view as a bit mask.

public final int getMeasuredState ()

Since: API Level 11

Return only the state bits of 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 final int getMeasuredWidth ()

Since: API Level 1

Like getMeasuredWidthAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

Returns
  • The raw measured width of this view.

public final int getMeasuredWidthAndState ()

Since: API Level 11

Return the full width measurement information for this view as computed by the most recent call to 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.

Returns
  • The measured width of this view as a bit mask.

public int getNextFocusDownId ()

Since: API Level 1

Gets the id of the view to use when the next focus is FOCUS_DOWN.

Related XML Attributes
Returns
  • The next focus ID, or NO_ID if the framework should decide automatically.

public int getNextFocusForwardId ()

Since: API Level 11

Gets the id of the view to use when the next focus is FOCUS_FORWARD.

Related XML Attributes
Returns
  • The next focus ID, or NO_ID if the framework should decide automatically.

public int getNextFocusLeftId ()

Since: API Level 1

Gets the id of the view to use when the next focus is FOCUS_LEFT.

Related XML Attributes
Returns
  • The next focus ID, or NO_ID if the framework should decide automatically.

public int getNextFocusRightId ()

Since: API Level 1

Gets the id of the view to use when the next focus is FOCUS_RIGHT.

Related XML Attributes
Returns
  • The next focus ID, or NO_ID if the framework should decide automatically.

public int getNextFocusUpId ()

Since: API Level 1

Gets the id of the view to use when the next focus is FOCUS_UP.

Related XML Attributes
Returns
  • The next focus ID, or NO_ID if the framework should decide automatically.

public View.OnFocusChangeListener getOnFocusChangeListener ()

Since: API Level 1

Returns the focus-change callback registered for this view.

Returns
  • The callback, or null if one is not registered.

public int getOverScrollMode ()

Since: API Level 9

Returns the over-scroll mode for this view. The result will be one of 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.

Returns
  • This view's over-scroll mode.

public int getPaddingBottom ()

Since: API Level 1

Returns the bottom padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
  • the bottom padding in pixels

public int getPaddingLeft ()

Since: API Level 1

Returns the left padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
  • the left padding in pixels

public int getPaddingRight ()

Since: API Level 1

Returns the right padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
  • the right padding in pixels

public int getPaddingTop ()

Since: API Level 1

Returns the top padding of this view.

Returns
  • the top padding in pixels

public final ViewParent getParent ()

Since: API Level 1

Gets the parent of this view. Note that the parent is a ViewParent and not necessarily a View.

Returns
  • Parent of this view.

public float getPivotX ()

Since: API Level 11

The x location of the point around which the view is rotated and scaled.

Returns
  • The x location of the pivot point.

public float getPivotY ()

Since: API Level 11

The y location of the point around which the view is rotated and scaled.

Returns
  • The y location of the pivot point.

public Resources getResources ()

Since: API Level 1

Returns the resources associated with this view.

Returns
  • Resources object.

public final int getRight ()

Since: API Level 1

Right position of this view relative to its parent.

Returns
  • The right edge of this view, in pixels.

public View getRootView ()

Since: API Level 1

Finds the topmost view in the current view hierarchy.

Returns
  • the topmost view containing this view

public float getRotation ()

Since: API Level 11

The degrees that the view is rotated around the pivot point.

Returns
  • The degrees of rotation.

public float getRotationX ()

Since: API Level 11

The degrees that the view is rotated around the horizontal axis through the pivot point.

Returns
  • The degrees of X rotation.

public float getRotationY ()

Since: API Level 11

The degrees that the view is rotated around the vertical axis through the pivot point.

Returns
  • The degrees of Y rotation.

public float getScaleX ()

Since: API Level 11

The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width. A value of 1, the default, means that no scaling is applied.

By default, this is 1.0f.

Returns
  • The scaling factor.

public float getScaleY ()

Since: API Level 11

The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height. A value of 1, the default, means that no scaling is applied.

By default, this is 1.0f.

Returns
  • The scaling factor.

public int getScrollBarStyle ()

Since: API Level 1

Returns the current scrollbar style.

Returns
  • the current scrollbar style

public final int getScrollX ()

Since: API Level 1

Return the scrolled left position of this view. This is the left edge of the displayed part of your view. You do not need to draw any pixels farther left, since those are outside of the frame of your view on screen.

Returns
  • The left edge of the displayed part of your view, in pixels.

public final int getScrollY ()

Since: API Level 1

Return the scrolled top position of this view. This is the top edge of the displayed part of your view. You do not need to draw any pixels above it, since those are outside of the frame of your view on screen.

Returns
  • The top edge of the displayed part of your view, in pixels.

public int getSolidColor ()

Since: API Level 1

Override this if your view is known to always be drawn on top of a solid color background, and needs to draw fading edges. Returning a non-zero color enables the view system to optimize the drawing of the fading edges. If you do return a non-zero color, the alpha should be set to 0xFF.

Returns
  • The known solid color background for this view, or 0 if the color may vary

public int getSystemUiVisibility ()

Since: API Level 11

Returns the status bar visibility that this view has requested.

public Object getTag (int key)

Since: API Level 4

Returns the tag associated with this view and the specified key.

Parameters
key The key identifying the tag
Returns
  • the Object stored in this view as a tag

public Object getTag ()

Since: API Level 1

Returns this view's tag.

Returns
  • the Object stored in this view as a tag

public final int getTop ()

Since: API Level 1

Top position of this view relative to its parent.

Returns
  • The top of this view, in pixels.

public TouchDelegate getTouchDelegate ()

Since: API Level 1

Gets the TouchDelegate for this View.

public ArrayList<View> getTouchables ()

Since: API Level 1

Find and return all touchable views that are descendants of this view, possibly including this view if it is touchable itself.

Returns
  • A list of touchable views

public float getTranslationX ()

Since: API Level 11

The horizontal location of this view relative to its left position. This position is post-layout, in addition to wherever the object's layout placed it.

Returns
  • The horizontal position of this view relative to its left position, in pixels.

public float getTranslationY ()

Since: API Level 11

The horizontal location of this view relative to its top position. This position is post-layout, in addition to wherever the object's layout placed it.

Returns
  • The vertical position of this view relative to its top position, in pixels.

public int getVerticalFadingEdgeLength ()

Since: API Level 1

Returns the size of the vertical faded edges used to indicate that more content in this view is visible.

Related XML Attributes
Returns
  • The size in pixels of the vertical faded edge or 0 if vertical faded edges are not enabled for this view.

public int getVerticalScrollbarPosition ()

Since: API Level 11

Returns
  • The position where the vertical scroll bar will show, if applicable.

public int getVerticalScrollbarWidth ()

Since: API Level 1

Returns the width of the vertical scrollbar.

Returns
  • The width in pixels of the vertical scrollbar or 0 if there is no vertical scrollbar.

public ViewTreeObserver getViewTreeObserver ()

Since: API Level 1

Returns the ViewTreeObserver for this view's hierarchy. The view tree observer can be used to get notifications when global events, like layout, happen. The returned ViewTreeObserver observer is not guaranteed to remain valid for the lifetime of this View. If the caller of this method keeps a long-lived reference to ViewTreeObserver, it should always check for the return value of isAlive().

Returns
  • The ViewTreeObserver for this view's hierarchy.

public int getVisibility ()

Since: API Level 1

Returns the visibility status for this view.

Related XML Attributes
Returns

public final int getWidth ()

Since: API Level 1

Return the width of the your view.

Returns
  • The width of your view, in pixels.

public IBinder getWindowToken ()

Since: API Level 1

Retrieve a unique token identifying the window this view is attached to.

Returns

public int getWindowVisibility ()

Since: API Level 1

Returns the current visibility of the window this view is attached to (either GONE, INVISIBLE, or VISIBLE).

Returns
  • Returns the current visibility of the view's window.

public void getWindowVisibleDisplayFrame (Rect outRect)

Since: API Level 3

Retrieve the overall visible display size in which the window this view is attached to has been positioned in. This takes into account screen decorations above the window, for both cases where the window itself is being position inside of them or the window is being placed under then and covered insets are used for the window to position its content inside. In effect, this tells you the available area where content can be placed and remain visible to users.

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.

Parameters
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 float getX ()

Since: API Level 11

The visual x position of this view, in pixels. This is equivalent to the translationX property plus the current left property.

Returns
  • The visual x position of this view, in pixels.

public float getY ()

Since: API Level 11

The visual y position of this view, in pixels. This is equivalent to the translationY property plus the current top property.

Returns
  • The visual y position of this view, in pixels.

public boolean hasFocus ()

Since: API Level 1

Returns true if this view has focus iteself, or is the ancestor of the view that has focus.

Returns
  • True if this view has or contains focus, false otherwise.

public boolean hasFocusable ()

Since: API Level 1

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

Returns
  • True if the view is focusable or if the view contains a focusable View, false otherwise.

public boolean hasWindowFocus ()

Since: API Level 1

Returns true if this view is in a window that currently has window focus. Note that this is not the same as the view itself having focus.

Returns
  • True if this view is in a window that currently has window focus.

public static View inflate (Context context, int resource, ViewGroup root)

Since: API Level 1

Inflate a view from an XML resource. This convenience method wraps the LayoutInflater class, which provides a full range of options for view inflation.

Parameters
context The Context object for your activity or application.
resource The resource ID to inflate
root A view group that will be the parent. Used to properly inflate the layout_* parameters.
See Also

public void invalidate (Rect dirty)

Since: API Level 1

Mark the the area defined by dirty as needing to be drawn. If the view is visible, onDraw(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.

Parameters
dirty the rectangle representing the bounds of the dirty region

public void invalidate (int l, int t, int r, int b)

Since: API Level 1

Mark the the area defined by the rect (l,t,r,b) as needing to be drawn. The coordinates of the dirty rect are relative to the view. If the view is visible, onDraw(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().

Parameters
l the left position of the dirty region
t the top position of the dirty region
r the right position of the dirty region
b the bottom position of the dirty region

public void invalidate ()

Since: API Level 1

Invalidate the whole view. If the view is visible, onDraw(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().

public void invalidateDrawable (Drawable drawable)

Since: API Level 1

Invalidates the specified Drawable.

Parameters
drawable the drawable to invalidate

public boolean isActivated ()

Since: API Level 11

Indicates the activation state of this view.

Returns
  • true if the view is activated, false otherwise

public boolean isClickable ()

Since: API Level 1

Indicates whether this view reacts to click events or not.

Related XML Attributes
Returns
  • true if the view is clickable, false otherwise

public boolean isDirty ()

Since: API Level 11

True if this view has changed since the last time being drawn.

Returns
  • The dirty state of this view.

public boolean isDrawingCacheEnabled ()

Since: API Level 1

Indicates whether the drawing cache is enabled for this view.

Returns
  • true if the drawing cache is enabled

public boolean isDuplicateParentStateEnabled ()

Since: API Level 1

Indicates whether this duplicates its drawable state from its parent.

Returns
  • True if this view's drawable state is duplicated from the parent, false otherwise

public boolean isEnabled ()

Since: API Level 1

Returns the enabled status for this view. The interpretation of the enabled state varies by subclass.

Returns
  • True if this view is enabled, false otherwise.

public final boolean isFocusable ()

Since: API Level 1

Returns whether this View is able to take focus.

Related XML Attributes
Returns
  • True if this view can take focus, or false otherwise.

public final boolean isFocusableInTouchMode ()

Since: API Level 1

When a view is focusable, it may not want to take focus when in touch mode. For example, a button would like focus when the user is navigating via a D-pad so that the user can click on it, but once the user starts touching the screen, the button shouldn't take focus

Related XML Attributes
Returns
  • Whether the view is focusable in touch mode.

public boolean isFocused ()

Since: API Level 1

Returns true if this view has focus

Returns
  • True if this view has focus, false otherwise.

public boolean isHapticFeedbackEnabled ()

Since: API Level 3

Related XML Attributes
Returns
  • whether this view should have haptic feedback enabled for events long presses.

public boolean isHardwareAccelerated ()

Since: API Level 11

Indicates whether this view is attached to an 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 offscren Bitmap and its window is hardware accelerated, isHardwareAccelerated() will likely return false, and this method will return true.

Returns
  • True if the view is attached to a window and the window is hardware accelerated; false in any other case.

public boolean isHorizontalFadingEdgeEnabled ()

Since: API Level 1

Indicate whether the horizontal edges are faded when the view is scrolled horizontally.

Related XML Attributes
Returns
  • true if the horizontal edges should are faded on scroll, false otherwise

public boolean isHorizontalScrollBarEnabled ()

Since: API Level 1

Indicate whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.

Returns
  • true if the horizontal scrollbar should be painted, false otherwise

public boolean isInEditMode ()

Since: API Level 3

Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets.

Returns
  • True if this View is in edit mode, false otherwise.

public boolean isInTouchMode ()

Since: API Level 1

Returns whether the device is currently in touch mode. Touch mode is entered once the user begins interacting with the device by touch, and affects various things like whether focus is always visible to the user.

Returns
  • Whether the device is in touch mode.

public boolean isLayoutRequested ()

Since: API Level 1

Indicates whether or not this view's layout will be requested during the next hierarchy layout pass.

Returns
  • true if the layout will be forced during next layout pass

public boolean isLongClickable ()

Since: API Level 1

Indicates whether this view reacts to long click events or not.

Related XML Attributes
Returns
  • true if the view is long clickable, false otherwise

public boolean isOpaque ()

Since: API Level 7

Indicates whether this View is opaque. An opaque View guarantees that it will draw all the pixels overlapping its bounds using a fully opaque color. Subclasses of View should override this method whenever possible to indicate whether an instance is opaque. Opaque Views are treated in a special way by the View hierarchy, possibly allowing it to perform optimizations during invalidate/draw passes.

Returns
  • True if this View is guaranteed to be fully opaque, false otherwise.

public boolean isPressed ()

Since: API Level 1

Indicates whether the view is currently in pressed state. Unless setPressed(boolean) is explicitly called, only clickable views can enter the pressed state.

Returns
  • true if the view is currently pressed, false otherwise

public boolean isSaveEnabled ()

Since: API Level 1

Indicates whether this view will save its state (that is, whether its onSaveInstanceState() method will be called).

Related XML Attributes
Returns
  • Returns true if the view state saving is enabled, else false.

public boolean isSaveFromParentEnabled ()

Since: API Level 11

Indicates whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent. The default is true; if false, these views will not be saved unless saveHierarchyState(SparseArray) is called directly on this view.

Returns
  • Returns true if the view state saving from parent is enabled, else false.

public boolean isScrollbarFadingEnabled ()

Since: API Level 5

Returns true if scrollbars will fade when this view is not scrolling

Returns
  • true if scrollbar fading is enabled

public boolean isSelected ()

Since: API Level 1

Indicates the selection state of this view.

Returns
  • true if the view is selected, false otherwise

public boolean isShown ()

Since: API Level 1

Returns the visibility of this view and all of its ancestors

Returns
  • True if this view and all of its ancestors are VISIBLE

public boolean isSoundEffectsEnabled ()

Since: API Level 1

Related XML Attributes
Returns
  • whether this view should have sound effects enabled for events such as clicking and touching.

public boolean isVerticalFadingEdgeEnabled ()

Since: API Level 1

Indicate whether the vertical edges are faded when the view is scrolled horizontally.

Related XML Attributes
Returns
  • true if the vertical edges should are faded on scroll, false otherwise

public boolean isVerticalScrollBarEnabled ()

Since: API Level 1

Indicate whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.

Returns
  • true if the vertical scrollbar should be painted, false otherwise

public void jumpDrawablesToCurrentState ()

Since: API Level 11

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

public void layout (int l, int t, int r, int b)

Since: API Level 1

Assign a size and position to a view and all of its descendants

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.

Parameters
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent

public final void measure (int widthMeasureSpec, int heightMeasureSpec)

Since: API Level 1

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 mesurement work of a view is performed in onMeasure(int, int), called by this method. Therefore, only onMeasure(int, int) can and must be overriden by subclasses.

Parameters
widthMeasureSpec Horizontal space requirements as imposed by the parent
heightMeasureSpec Vertical space requirements as imposed by the parent

public void offsetLeftAndRight (int offset)

Since: API Level 1

Offset this view's horizontal location by the specified amount of pixels.

Parameters
offset the numer of pixels to offset the view by

public void offsetTopAndBottom (int offset)

Since: API Level 1

Offset this view's vertical location by the specified number of pixels.

Parameters
offset the number of pixels to offset the view by

public boolean onCheckIsTextEditor ()

Since: API Level 3

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. Subclasses should override this if they implement 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.

Returns
  • Returns true if this view is a text editor, else false.

public InputConnection onCreateInputConnection (EditorInfo outAttrs)

Since: API Level 3

Create a new InputConnection for an InputMethod to interact with the view. The default implementation returns null, since it doesn't support input methods. You can override this to implement such support. This is only needed for views that take focus and text input.

When implementing this, you probably also want to implement onCheckIsTextEditor() to indicate you will return a non-null InputConnection.

Parameters
outAttrs Fill in with attribute information about the connection.

public boolean onDragEvent (DragEvent event)

Since: API Level 11

Handles drag events sent by the system following a call to startDrag().

When the system calls this method, it passes a DragEvent object. A call to 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.

Parameters
event The DragEvent sent by the system. The getAction() method returns an action type constant defined in DragEvent, indicating the type of drag event represented by this object.
Returns
  • true if the method was successful, otherwise false.

    The method should return true in response to an action type of ACTION_DRAG_STARTED to receive drag events for the current operation.

    The method should also return true in response to an action type of ACTION_DROP if it consumed the drop, or false if it didn't.

public boolean onFilterTouchEventForSecurity (MotionEvent event)

Since: API Level 9

Filter the touch event to apply security policies.

Parameters
event The motion event to be filtered.
Returns
  • True if the event should be dispatched, false if the event should be dropped.

public void onFinishTemporaryDetach ()

Since: API Level 3

Called after onStartTemporaryDetach() when the container is done changing the view.

public boolean onGenericMotionEvent (MotionEvent event)

Since: API Level 12

Implement this method to handle generic motion events.

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 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); }

Parameters
event The generic motion event being processed.
Returns
  • Return true if you have consumed the event, false if you haven't. The default implementation always returns false.

public boolean onKeyDown (int keyCode, KeyEvent event)

Since: API Level 1

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released, if the view is enabled and clickable.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyLongPress (int keyCode, KeyEvent event)

Since: API Level 5

Default implementation of KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle the event).

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event)

Since: API Level 1

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

Parameters
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.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyPreIme (int keyCode, KeyEvent event)

Since: API Level 3

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyShortcut (int keyCode, KeyEvent event)

Since: API Level 1

Called on the focused view when a key shortcut event is not handled. Override this method to implement local key shortcuts for the View. Key shortcuts can also be implemented by setting the shortcut property of menu items.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyUp (int keyCode, KeyEvent event)

Since: API Level 1

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public void onStartTemporaryDetach ()

Since: API Level 3

This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent. It will either be followed by onFinishTemporaryDetach() or onDetachedFromWindow() when the container is done.

public boolean onTouchEvent (MotionEvent event)

Since: API Level 1

Implement this method to handle touch screen motion events.

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public boolean onTrackballEvent (MotionEvent event)

Since: API Level 1

Implement this method to handle trackball motion events. The relative movement of the trackball since the last event can be retrieve with 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).

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public void onWindowFocusChanged (boolean hasWindowFocus)

Since: API Level 1

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters
hasWindowFocus True if the window containing this view now has focus, false otherwise.

public boolean performClick ()

Since: API Level 1

Call this view's OnClickListener, if it is defined.

Returns
  • True there was an assigned OnClickListener that was called, false otherwise is returned.

public boolean performHapticFeedback (int feedbackConstant, int flags)

Since: API Level 3

BZZZTT!!1!

Like performHapticFeedback(int), with additional options.

Parameters
feedbackConstant One of the constants defined in HapticFeedbackConstants
flags Additional flags as per HapticFeedbackConstants.

public boolean performHapticFeedback (int feedbackConstant)

Since: API Level 3

BZZZTT!!1!

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.

Parameters
feedbackConstant One of the constants defined in HapticFeedbackConstants

public boolean performLongClick ()

Since: API Level 1

Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.

Returns
  • True if one of the above receivers consumed the event, false otherwise.

public void playSoundEffect (int soundConstant)

Since: API Level 1

Play a sound effect for this view.

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.

Parameters
soundConstant One of the constants defined in SoundEffectConstants

public boolean post (Runnable action)

Since: API Level 1

Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.

Parameters
action The Runnable that will be executed.
Returns
  • Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

public boolean postDelayed (Runnable action, long delayMillis)

Since: API Level 1

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.

Parameters
action The Runnable that will be executed.
delayMillis The delay (in milliseconds) until the Runnable will be executed.
Returns
  • true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.

public void postInvalidate (int left, int top, int right, int bottom)

Since: API Level 1

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.

Parameters
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.

public void postInvalidate ()

Since: API Level 1

Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

See Also

public void postInvalidateDelayed (long delayMilliseconds, int left, int top, int right, int bottom)

Since: API Level 1

Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.

Parameters
delayMilliseconds the duration in milliseconds to delay the invalidation by
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.

public void postInvalidateDelayed (long delayMilliseconds)

Since: API Level 1

Cause an invalidate to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.

Parameters
delayMilliseconds the duration in milliseconds to delay the invalidation by

public void refreshDrawableState ()

Since: API Level 1

Call this to force a view to update its drawable state. This will cause drawableStateChanged to be called on this view. Views that are interested in the new state should call getDrawableState.

public boolean removeCallbacks (Runnable action)

Since: API Level 1

Removes the specified Runnable from the message queue.

Parameters
action The Runnable to remove from the message handling queue
Returns
  • true if this view could ask the Handler to remove the Runnable, false otherwise. When the returned value is true, the Runnable may or may not have been actually removed from the message queue (for instance, if the Runnable was not in the queue already.)

public void removeOnAttachStateChangeListener (View.OnAttachStateChangeListener listener)

Since: API Level 12

Remove a listener for attach state changes. The listener will receive no further notification of window attach/detach events.

Parameters
listener Listener to remove

public void removeOnLayoutChangeListener (View.OnLayoutChangeListener listener)

Since: API Level 11

Remove a listener for layout changes.

Parameters
listener The listener for layout bounds change.

public boolean requestFocus (int direction, Rect previouslyFocusedRect)

Since: API Level 1

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. The rectangle can help give larger views a finer grained hint about where focus is coming from, and therefore, where to show selection, or forward focus change internally. A view will not actually take focus if it is not focusable (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 getDescendantFocusability() equal to 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.

Parameters
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
previouslyFocusedRect 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.
Returns
  • Whether this view or one of its descendants actually took focus.

public final boolean requestFocus (int direction)

Since: API Level 1

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. A view will not actually take focus if it is not focusable (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.

Parameters
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
Returns
  • Whether this view or one of its descendants actually took focus.

public final boolean requestFocus ()

Since: API Level 1

Call this to try to give focus to a specific view or to one of its descendants. A view will not actually take focus if it is not focusable (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.

Returns
  • Whether this view or one of its descendants actually took focus.

public final boolean requestFocusFromTouch ()

Since: API Level 1

Call this to try to give focus to a specific view or to one of its descendants. This is a special variant of requestFocus() that will allow views that are not focuable in touch mode to request focus when they are touched.

Returns
  • Whether this view or one of its descendants actually took focus.
See Also

public void requestLayout ()

Since: API Level 1

Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree.

public boolean requestRectangleOnScreen (Rect rectangle)

Since: API Level 1

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

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.

Parameters
rectangle The rectangle.
Returns
  • Whether any parent scrolled.

public boolean requestRectangleOnScreen (Rect rectangle, boolean immediate)

Since: API Level 1

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

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.

Parameters
rectangle The rectangle.
immediate True to forbid animated scrolling, false otherwise
Returns
  • Whether any parent scrolled.

public static int resolveSize (int size, int measureSpec)

Since: API Level 1

Version of resolveSizeAndState(int, int, int) returning only the MEASURED_SIZE_MASK bits of the result.

public static int resolveSizeAndState (int size, int measureSpec, int childMeasuredState)

Since: API Level 11

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

Parameters
size How big the view wants to be
measureSpec Constraints imposed by the parent
Returns

public void restoreHierarchyState (SparseArray<Parcelable> container)

Since: API Level 1

Restore this view hierarchy's frozen state from the given container.

Parameters
container The SparseArray which holds previously frozen states.

public void saveHierarchyState (SparseArray<Parcelable> container)

Since: API Level 1

Store this view hierarchy's frozen state into the given container.

Parameters
container The SparseArray in which to save the view's state.

public void scheduleDrawable (Drawable who, Runnable what, long when)

Since: API Level 1

Schedules an action on a drawable to occur at a specified time.

Parameters
who the recipient of the action
what the action to run on the drawable
when the time at which the action must occur. Uses the uptimeMillis() timebase.

public void scrollBy (int x, int y)

Since: API Level 1

Move the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
x the amount of pixels to scroll by horizontally
y the amount of pixels to scroll by vertically

public void scrollTo (int x, int y)

Since: API Level 1

Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
x the x position to scroll to
y the y position to scroll to

public void sendAccessibilityEvent (int eventType)

Since: API Level 4

Handles the request for sending an AccessibilityEvent given the event type. The method must first check if accessibility is on via calling isEnabled(), obtain an AccessibilityEvent from the event pool through calling obtain(int), populate the event, and send it for dispatch via calling sendAccessibilityEvent(AccessibilityEvent).

Parameters
eventType The event type.

public void sendAccessibilityEventUnchecked (AccessibilityEvent event)

Since: API Level 4

Handles the request for sending an AccessibilityEvent. The method does not guarantee to check if accessibility is on before sending the event for dispatch. It is responsibility of the caller to do the check via calling isEnabled().

Parameters
event The event.

public void setActivated (boolean activated)

Since: API Level 11

Changes the activated state of this view. A view can be activated or not. Note that activation is not the same as selection. Selection is a transient property, representing the view (hierarchy) the user is currently interacting with. Activation is a longer-term state that the user can move views in and out of. For example, in a list view with single or multiple selection enabled, the views in the current selection set are activated. (Um, yeah, we are deeply sorry about the terminology here.) The activated state is propagated down to children of the view it is set on.

Parameters
activated true if the view must be activated, false otherwise

public void setAlpha (float alpha)

Since: API Level 11

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.

Related XML Attributes
Parameters
alpha The opacity of the view.

public void setAnimation (Animation animation)

Since: API Level 1

Sets the next animation to play for this view. If you want the animation to play immediately, use startAnimation. 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 will be invalidated when the animation is supposed to start.

Parameters
animation The next animation, or null.

public void setBackgroundColor (int color)

Since: API Level 1

Sets the background color for this view.

Parameters
color the color of the background

public void setBackgroundDrawable (Drawable d)

Since: API Level 1

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

Parameters
d The Drawable to use as the background, or null to remove the background

public void setBackgroundResource (int resid)

Since: API Level 1

Set the background to a given resource. The resource should refer to a Drawable object or 0 to remove the background.

Related XML Attributes
Parameters
resid The identifier of the resource.

public final void setBottom (int bottom)

Since: API Level 11

Sets the bottom position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
bottom The bottom of this view, in pixels.

public void setCameraDistance (float distance)

Since: API Level 12

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.

Parameters
distance The distance in "depth pixels", if negative the opposite value is used

public void setClickable (boolean clickable)

Since: API Level 1

Enables or disables click events for this view. When a view is clickable it will change its state to "pressed" on every click. Subclasses should set the view clickable to visually react to user's clicks.

Related XML Attributes
Parameters
clickable true to make the view clickable, false otherwise
See Also

public void setContentDescription (CharSequence contentDescription)

Since: API Level 4

Sets the 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).

Related XML Attributes
Parameters
contentDescription The content description.

public void setDrawingCacheBackgroundColor (int color)

Since: API Level 1

Setting a solid background color for the drawing cache's bitmaps will improve perfromance and memory usage. Note, though that this should only be used if this view will always be drawn on top of a solid color.

Parameters
color The background color to use for the drawing cache's bitmap

public void setDrawingCacheEnabled (boolean enabled)

Since: API Level 1

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().

Parameters
enabled true to enable the drawing cache, false otherwise

public void setDrawingCacheQuality (int quality)

Since: API Level 1

Set the drawing cache quality of this view. This value is used only when the drawing cache is enabled

Related XML Attributes

public void setDuplicateParentStateEnabled (boolean enabled)

Since: API Level 1

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.

Parameters
enabled True to enable duplication of the parent's drawable state, false to disable it.

public void setEnabled (boolean enabled)

Since: API Level 1

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

Parameters
enabled True if this view is enabled, false otherwise.

public void setFadingEdgeLength (int length)

Since: API Level 1

Set the size of the faded edge used to indicate that more content in this view is available. Will not change whether the fading edge is enabled; use setVerticalFadingEdgeEnabled(boolean) or setHorizontalFadingEdgeEnabled(boolean) to enable the fading edge for the vertical or horizontal fading edges.

Parameters
length The size in pixels of the faded edge used to indicate that more content in this view is visible.

public void setFilterTouchesWhenObscured (boolean enabled)

Since: API Level 9

Sets whether the framework should discard touches when the view's window is obscured by another visible window. Refer to the View security documentation for more details.

Related XML Attributes
Parameters
enabled True if touch filtering should be enabled.

public void setFocusable (boolean focusable)

Since: API Level 1

Set whether this view can receive the focus. Setting this to false will also ensure that this view is not focusable in touch mode.

Related XML Attributes
Parameters
focusable If true, this view can receive the focus.

public void setFocusableInTouchMode (boolean focusableInTouchMode)

Since: API Level 1

Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.

Related XML Attributes
Parameters
focusableInTouchMode If true, this view can receive the focus while in touch mode.

public void setHapticFeedbackEnabled (boolean hapticFeedbackEnabled)

Since: API Level 3

Set whether this view should have haptic feedback for events such as long presses.

You may wish to disable haptic feedback if your view already controls its own haptic feedback.

Related XML Attributes
Parameters
hapticFeedbackEnabled whether haptic feedback enabled for this view.

public void setHorizontalFadingEdgeEnabled (boolean horizontalFadingEdgeEnabled)

Since: API Level 1

Define whether the horizontal edges should be faded when this view is scrolled horizontally.

Related XML Attributes
Parameters
horizontalFadingEdgeEnabled true if the horizontal edges should be faded when the view is scrolled horizontally

public void setHorizontalScrollBarEnabled (boolean horizontalScrollBarEnabled)

Since: API Level 1

Define whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.

Parameters
horizontalScrollBarEnabled true if the horizontal scrollbar should be painted

public void setId (int id)

Since: API Level 1

Sets the identifier for this view. The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.

Related XML Attributes
Parameters
id a number used to identify the view

public void setKeepScreenOn (boolean keepScreenOn)

Since: API Level 1

Controls whether the screen should remain on, modifying the value of KEEP_SCREEN_ON.

Related XML Attributes
Parameters
keepScreenOn Supply true to set KEEP_SCREEN_ON.

public void setLayerType (int layerType, Paint paint)

Since: API Level 11

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.

Related XML Attributes
Parameters
layerType The ype 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

public void setLayoutParams (ViewGroup.LayoutParams params)

Since: API Level 1

Set the layout parameters associated with this view. These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children.

Parameters
params The layout parameters for this view, cannot be null

public final void setLeft (int left)

Since: API Level 11

Sets the left position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
left The bottom of this view, in pixels.

public void setLongClickable (boolean longClickable)

Since: API Level 1

Enables or disables long click events for this view. When a view is long clickable it reacts to the user holding down the button for a longer duration than a tap. This event can either launch the listener or a context menu.

Related XML Attributes
Parameters
longClickable true to make the view long clickable, false otherwise

public void setMinimumHeight (int minHeight)

Since: API Level 1

Sets the minimum height of the view. It is not guaranteed the view will be able to achieve this minimum height (for example, if its parent layout constrains it with less available height).

Parameters
minHeight The minimum height the view will try to be.

public void setMinimumWidth (int minWidth)

Since: API Level 1

Sets the minimum width of the view. It is not guaranteed the view will be able to achieve this minimum width (for example, if its parent layout constrains it with less available width).

Parameters
minWidth The minimum width the view will try to be.

public void setNextFocusDownId (int nextFocusDownId)

Since: API Level 1

Sets the id of the view to use when the next focus is FOCUS_DOWN.

Related XML Attributes
Parameters
nextFocusDownId The next focus ID, or NO_ID if the framework should decide automatically.

public void setNextFocusForwardId (int nextFocusForwardId)

Since: API Level 11

Sets the id of the view to use when the next focus is FOCUS_FORWARD.

Related XML Attributes
Parameters
nextFocusForwardId The next focus ID, or NO_ID if the framework should decide automatically.

public void setNextFocusLeftId (int nextFocusLeftId)

Since: API Level 1

Sets the id of the view to use when the next focus is FOCUS_LEFT.

Related XML Attributes
Parameters
nextFocusLeftId The next focus ID, or NO_ID if the framework should decide automatically.

public void setNextFocusRightId (int nextFocusRightId)

Since: API Level 1

Sets the id of the view to use when the next focus is FOCUS_RIGHT.

Related XML Attributes
Parameters
nextFocusRightId The next focus ID, or NO_ID if the framework should decide automatically.

public void setNextFocusUpId (int nextFocusUpId)

Since: API Level 1

Sets the id of the view to use when the next focus is FOCUS_UP.

Related XML Attributes
Parameters
nextFocusUpId The next focus ID, or NO_ID if the framework should decide automatically.

public void setOnClickListener (View.OnClickListener l)

Since: API Level 1

Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

Parameters
l The callback that will run

public void setOnCreateContextMenuListener (View.OnCreateContextMenuListener l)

Since: API Level 1

Register a callback to be invoked when the context menu for this view is being built. If this view is not long clickable, it becomes long clickable.

Parameters
l The callback that will run

public void setOnDragListener (View.OnDragListener l)

Since: API Level 11

Register a drag event listener callback object for this View. The parameter is an implementation of View.OnDragListener. To send a drag event to a View, the system calls the onDrag(View, DragEvent) method.

Parameters
l An implementation of View.OnDragListener.

public void setOnFocusChangeListener (View.OnFocusChangeListener l)

Since: API Level 1

Register a callback to be invoked when focus of this view changed.

Parameters
l The callback that will run.

public void setOnGenericMotionListener (View.OnGenericMotionListener l)

Since: API Level 12

Register a callback to be invoked when a generic motion event is sent to this view.

Parameters
l the generic motion listener to attach to this view

public void setOnKeyListener (View.OnKeyListener l)

Since: API Level 1

Register a callback to be invoked when a key is pressed in this view.

Parameters
l the key listener to attach to this view

public void setOnLongClickListener (View.OnLongClickListener l)

Since: API Level 1

Register a callback to be invoked when this view is clicked and held. If this view is not long clickable, it becomes long clickable.

Parameters
l The callback that will run

public void setOnSystemUiVisibilityChangeListener (View.OnSystemUiVisibilityChangeListener l)

Since: API Level 11

Set a listener to receive callbacks when the visibility of the system bar changes.

Parameters
l The View.OnSystemUiVisibilityChangeListener to receive callbacks.

public void setOnTouchListener (View.OnTouchListener l)

Since: API Level 1

Register a callback to be invoked when a touch event is sent to this view.

Parameters
l the touch listener to attach to this view

public void setOverScrollMode (int overScrollMode)

Since: API Level 9

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

Parameters
overScrollMode The new over-scroll mode for this view.

public void setPadding (int left, int top, int right, int bottom)

Since: API Level 1

Sets the padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom() may be different from the values set in this call.

Parameters
left the left padding in pixels
top the top padding in pixels
right the right padding in pixels
bottom the bottom padding in pixels

public void setPivotX (float pivotX)

Since: API Level 11

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

Related XML Attributes
Parameters
pivotX The x location of the pivot point.

public void setPivotY (float pivotY)

Since: API Level 11

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

Related XML Attributes
Parameters
pivotY The y location of the pivot point.

public void setPressed (boolean pressed)

Since: API Level 1

Sets the pressed state for this view.

Parameters
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.

public final void setRight (int right)

Since: API Level 11

Sets the right position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
right The bottom of this view, in pixels.

public void setRotation (float rotation)

Since: API Level 11

Sets the degrees that the view is rotated around the pivot point. Increasing values result in clockwise rotation.

Related XML Attributes
Parameters
rotation The degrees of rotation.

public void setRotationX (float rotationX)

Since: API Level 11

Sets the degrees that the view is rotated around the horizontal axis through the pivot point. Increasing values result in clockwise rotation from the viewpoint of looking down the x axis. When rotating large views, it is recommended to adjust the camera distance accordingly. Refer to setCameraDistance(float) for more information.

Related XML Attributes
Parameters
rotationX The degrees of X rotation.

public void setRotationY (float rotationY)

Since: API Level 11

Sets the degrees that the view is rotated around the vertical axis through the pivot point. Increasing values result in counter-clockwise rotation from the viewpoint of looking down the y axis. When rotating large views, it is recommended to adjust the camera distance accordingly. Refer to setCameraDistance(float) for more information.

Related XML Attributes
Parameters
rotationY The degrees of Y rotation.

public void setSaveEnabled (boolean enabled)

Since: API Level 1

Controls whether the saving of this view's state is enabled (that is, whether its onSaveInstanceState() method will be called). Note that even if freezing is enabled, the view still must have an id assigned to it (via setId()) 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.

Related XML Attributes
Parameters
enabled Set to false to disable state saving, or true (the default) to allow it.

public void setSaveFromParentEnabled (boolean enabled)

Since: API Level 11

Controls whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent. The default is true; if false, these views will not be saved unless saveHierarchyState(SparseArray) is called directly on this view.

Parameters
enabled Set to false to disable state saving, or true (the default) to allow it.

public void setScaleX (float scaleX)

Since: API Level 11

Sets the amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width. A value of 1 means that no scaling is applied.

Related XML Attributes
Parameters
scaleX The scaling factor.

public void setScaleY (float scaleY)

Since: API Level 11

Sets the amount that the view is scaled in Y around the pivot point, as a proportion of the view's unscaled width. A value of 1 means that no scaling is applied.

Related XML Attributes
Parameters
scaleY The scaling factor.

public void setScrollBarStyle (int style)

Since: API Level 1

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.

Parameters
style the style of the scrollbars. Should be one of SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

public void setScrollContainer (boolean isScrollContainer)

Since: API Level 3

Change whether this view is one of the set of scrollable containers in its window. This will be used to determine whether the window can resize or must pan when a soft input area is open -- scrollable containers allow the window to use resize mode since the container will appropriately shrink.

public void setScrollbarFadingEnabled (boolean fadeScrollbars)

Since: API Level 5

Define whether scrollbars will fade when the view is not scrolling.

Parameters
fadeScrollbars wheter to enable fading

public void setSelected (boolean selected)

Since: API Level 1

Changes the selection state of this view. A view can be selected or not. Note that selection is not the same as focus. Views are typically selected in the context of an AdapterView like ListView or GridView; the selected view is the view that is highlighted.

Parameters
selected true if the view must be selected, false otherwise

public void setSoundEffectsEnabled (boolean soundEffectsEnabled)

Since: API Level 1

Set whether this view should have sound effects enabled for events such as clicking and touching.

You may wish to disable sound effects for a view if you already play sounds, for instance, a dial key that plays dtmf tones.

Related XML Attributes
Parameters
soundEffectsEnabled whether sound effects are enabled for this view.

public void setSystemUiVisibility (int visibility)

Since: API Level 11

Request that the visibility of the status bar be changed.

Parameters
visibility Either STATUS_BAR_VISIBLE or STATUS_BAR_HIDDEN.

public void setTag (int key, Object tag)

Since: API Level 4

Sets a tag associated with this view and a key. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure. The specified key should be an id declared in the resources of the application to ensure it is unique (see the ID resource type). Keys identified as belonging to the Android framework or not associated with any package will cause an IllegalArgumentException to be thrown.

Parameters
key The key identifying the tag
tag An Object to tag the view with
Throws
IllegalArgumentException If they specified key is not valid

public void setTag (Object tag)

Since: API Level 1

Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.

Parameters
tag an Object to tag the view with

public final void setTop (int top)

Since: API Level 11

Sets the top position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
top The top of this view, in pixels.

public void setTouchDelegate (TouchDelegate delegate)

Since: API Level 1

Sets the TouchDelegate for this View.

public void setTranslationX (float translationX)

Since: API Level 11

Sets the horizontal location of this view relative to its left position. This effectively positions the object post-layout, in addition to wherever the object's layout placed it.

Related XML Attributes
Parameters
translationX The horizontal position of this view relative to its left position, in pixels.

public void setTranslationY (float translationY)

Since: API Level 11

Sets the vertical location of this view relative to its top position. This effectively positions the object post-layout, in addition to wherever the object's layout placed it.

Related XML Attributes
Parameters
translationY The vertical position of this view relative to its top position, in pixels.

public void setVerticalFadingEdgeEnabled (boolean verticalFadingEdgeEnabled)

Since: API Level 1

Define whether the vertical edges should be faded when this view is scrolled vertically.

Related XML Attributes
Parameters
verticalFadingEdgeEnabled true if the vertical edges should be faded when the view is scrolled vertically

public void setVerticalScrollBarEnabled (boolean verticalScrollBarEnabled)

Since: API Level 1

Define whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.

Parameters
verticalScrollBarEnabled true if the vertical scrollbar should be painted

public void setVerticalScrollbarPosition (int position)

Since: API Level 11

Set the position of the vertical scroll bar. Should be one of SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT or SCROLLBAR_POSITION_RIGHT.

Parameters
position Where the vertical scroll bar should be positioned.

public void setVisibility (int visibility)

Since: API Level 1

Set the enabled state of this view.

Related XML Attributes
Parameters
visibility One of VISIBLE, INVISIBLE, or GONE.

public void setWillNotCacheDrawing (boolean willNotCacheDrawing)

Since: API Level 1

When a View's drawing cache is enabled, drawing is redirected to an offscreen bitmap. Some views, like an ImageView, must be able to bypass this mechanism if they already draw a single bitmap, to avoid unnecessary usage of the memory.

Parameters
willNotCacheDrawing true if this view does not cache its drawing, false otherwise

public void setWillNotDraw (boolean willNotDraw)

Since: API Level 1

If this view doesn't do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(Canvas) you should clear this flag.

Parameters
willNotDraw whether or not this View draw on its own

public void setX (float x)

Since: API Level 11

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

Parameters
x The visual x position of this view, in pixels.

public void setY (float y)

Since: API Level 11

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

Parameters
y The visual y position of this view, in pixels.

public boolean showContextMenu ()

Since: API Level 1

Bring up the context menu for this view.

Returns
  • Whether a context menu was displayed.

public ActionMode startActionMode (ActionMode.Callback callback)

Since: API Level 11

Start an action mode.

Parameters
callback Callback that will control the lifecycle of the action mode
Returns
  • The new action mode if it is started, null otherwise
See Also

public void startAnimation (Animation animation)

Since: API Level 1

Start the specified animation now.

Parameters
animation the animation to start now

public final boolean startDrag (ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)

Since: API Level 11

Starts a drag and drop operation. When your application calls this method, it passes a View.DragShadowBuilder object to the system. The system calls this object's onProvideShadowMetrics(Point, Point) to get metrics for the drag shadow, and then calls the object's 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 getAction() value of 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.

Parameters
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.
Returns
  • 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 void unscheduleDrawable (Drawable who)

Since: API Level 1

Unschedule any events associated with the given Drawable. This can be used when selecting a new Drawable into a view, so that the previous one is completely unscheduled.

Parameters
who The Drawable to unschedule.

public void unscheduleDrawable (Drawable who, Runnable what)

Since: API Level 1

Cancels a scheduled action on a drawable.

Parameters
who the recipient of the action
what the action to cancel

public boolean willNotCacheDrawing ()

Since: API Level 1

Returns whether or not this View can cache its drawing or not.

Returns
  • true if this view does not cache its drawing, false otherwise

public boolean willNotDraw ()

Since: API Level 1

Returns whether or not this View draws on its own.

Returns
  • true if this view has nothing to draw, false otherwise

Protected Methods

protected boolean awakenScrollBars (int startDelay)

Since: API Level 5

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.

Parameters
startDelay the delay, in milliseconds, after which the animation should start; when the delay is 0, the animation starts immediately
Returns
  • true if the animation is played, false otherwise

protected boolean awakenScrollBars (int startDelay, boolean invalidate)

Since: API Level 5

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.

Parameters
startDelay the delay, in milliseconds, after which the animation should start; when the delay is 0, the animation starts immediately
invalidate Wheter this method should call invalidate
Returns
  • true if the animation is played, false otherwise

protected boolean awakenScrollBars ()

Since: API Level 5

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).

Returns
  • true if the animation is played, false otherwise

protected int computeHorizontalScrollExtent ()

Since: API Level 1

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.

Returns
  • the horizontal extent of the scrollbar's thumb

protected int computeHorizontalScrollOffset ()

Since: API Level 1

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.

Returns
  • the horizontal offset of the scrollbar's thumb

protected int computeHorizontalScrollRange ()

Since: API Level 1

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.

Returns
  • the total horizontal range represented by the horizontal scrollbar

protected int computeVerticalScrollExtent ()

Since: API Level 1

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.

Returns
  • the vertical extent of the scrollbar's thumb

protected int computeVerticalScrollOffset ()

Since: API Level 1

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.

Returns
  • the vertical offset of the scrollbar's thumb

protected int computeVerticalScrollRange ()

Since: API Level 1

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().

Returns
  • the total vertical range represented by the vertical scrollbar

    The default range is the drawing height of this view.

protected void dispatchDraw (Canvas canvas)

Since: API Level 1

Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

Parameters
canvas the canvas on which to draw the view

protected void dispatchRestoreInstanceState (SparseArray<Parcelable> container)

Since: API Level 1

Called by restoreHierarchyState(SparseArray ) to retrieve the state for this view and its children. May be overridden to modify how restoreing happens to a view's children; for example, some views may want to not store state for their children.

Parameters
container The SparseArray which holds previously saved state.

protected void dispatchSaveInstanceState (SparseArray<Parcelable> container)

Since: API Level 1

Called by saveHierarchyState(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.

Parameters
container The SparseArray in which to save the view's state.

protected void dispatchSetActivated (boolean activated)

Since: API Level 11

Dispatch setActivated to all of this View's children.

Parameters
activated The new activated state

protected void dispatchSetPressed (boolean pressed)

Since: API Level 1

Dispatch setPressed to all of this View's children.

Parameters
pressed The new pressed state

protected void dispatchSetSelected (boolean selected)

Since: API Level 1

Dispatch setSelected to all of this View's children.

Parameters
selected The new selected state

protected void dispatchVisibilityChanged (View changedView, int visibility)

Since: API Level 8

Dispatch a view visibility change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
changedView The view whose visibility changed. Could be 'this' or an ancestor view.
visibility The new visibility of changedView: VISIBLE, INVISIBLE or GONE.

protected void drawableStateChanged ()

Since: API Level 1

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

Be sure to call through to the superclass when overriding this function.

See Also

protected boolean fitSystemWindows (Rect insets)

Since: API Level 1

Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag is set

Parameters
insets Insets for system windows
Returns
  • True if this view applied the insets, false otherwise

protected float getBottomFadingEdgeStrength ()

Since: API Level 1

Returns the strength, or intensity, of the bottom faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the bottom fade as a float between 0.0f and 1.0f

protected int getBottomPaddingOffset ()

Since: API Level 2

Amount by which to extend the bottom fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The bottom padding offset in pixels.

protected ContextMenu.ContextMenuInfo getContextMenuInfo ()

Since: API Level 1

Views should implement this if they have extra information to associate with the context menu. The return result is supplied as a parameter to the onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback.

Returns
  • Extra information about the item for which the context menu should be shown. This information will vary across different subclasses of View.

protected int getHorizontalScrollbarHeight ()

Since: API Level 1

Returns the height of the horizontal scrollbar.

Returns
  • The height in pixels of the horizontal scrollbar or 0 if there is no horizontal scrollbar.

protected float getLeftFadingEdgeStrength ()

Since: API Level 1

Returns the strength, or intensity, of the left faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the left fade as a float between 0.0f and 1.0f

protected int getLeftPaddingOffset ()

Since: API Level 2

Amount by which to extend the left fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The left padding offset in pixels.

protected float getRightFadingEdgeStrength ()

Since: API Level 1

Returns the strength, or intensity, of the right faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the right fade as a float between 0.0f and 1.0f

protected int getRightPaddingOffset ()

Since: API Level 2

Amount by which to extend the right fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The right padding offset in pixels.

protected int getSuggestedMinimumHeight ()

Since: API Level 1

Returns the suggested minimum height that the view should use. This returns the maximum of the view's minimum height and the background's minimum height (getMinimumHeight()).

When being used in onMeasure(int, int), the caller should still ensure the returned height is within the requirements of the parent.

Returns
  • The suggested minimum height of the view.

protected int getSuggestedMinimumWidth ()

Since: API Level 1

Returns the suggested minimum width that the view should use. This returns the maximum of the view's minimum width) and the background's minimum width (getMinimumWidth()).

When being used in onMeasure(int, int), the caller should still ensure the returned width is within the requirements of the parent.

Returns
  • The suggested minimum width of the view.

protected float getTopFadingEdgeStrength ()

Since: API Level 1

Returns the strength, or intensity, of the top faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the top fade as a float between 0.0f and 1.0f

protected int getTopPaddingOffset ()

Since: API Level 2

Amount by which to extend the top fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The top padding offset in pixels.

protected int getWindowAttachCount ()

Since: API Level 1

Returns
  • The number of times this view has been attached to a window

protected void initializeFadingEdge (TypedArray a)

Since: API Level 1

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.

Parameters
a the styled attributes set to initialize the fading edges from

protected void initializeScrollbars (TypedArray a)

Since: API Level 1

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.

Parameters
a the styled attributes set to initialize the scrollbars from

protected boolean isPaddingOffsetRequired ()

Since: API Level 2

If the View draws content inside its padding and enables fading edges, it needs to support padding offsets. Padding offsets are added to the fading edges to extend the length of the fade so that it covers pixels drawn inside the padding. Subclasses of this class should override this method if they need to draw content inside the padding.

Returns
  • True if padding offset must be applied, false otherwise.

protected static int[] mergeDrawableStates (int[] baseState, int[] additionalState)

Since: API Level 1

Merge your own state values in additionalState into the base state values baseState that were returned by onCreateDrawableState(int).

Parameters
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.
Returns
  • As a convenience, the baseState array you originally passed into the function is returned.

protected void onAnimationEnd ()

Since: API Level 1

Invoked by a parent ViewGroup to notify the end of the animation currently associated with this view. If you override this method, always call super.onAnimationEnd();

protected void onAnimationStart ()

Since: API Level 1

Invoked by a parent ViewGroup to notify the start of the animation currently associated with this view. If you override this method, always call super.onAnimationStart();

protected void onAttachedToWindow ()

Since: API Level 1

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

protected void onConfigurationChanged (Configuration newConfig)

Since: API Level 8

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characterstics. You only need to use this if you are not relying on the normal Activity mechanism of recreating the activity instance upon a configuration change.

Parameters
newConfig The new resource configuration.

protected void onCreateContextMenu (ContextMenu menu)

Since: API Level 1

Views should implement this if the view itself is going to add items to the context menu.

Parameters
menu the context menu to populate

protected int[] onCreateDrawableState (int extraSpace)

Since: API Level 1

Generate the new 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().

Parameters
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.
Returns
  • Returns an array holding the current Drawable state of the view.

protected void onDetachedFromWindow ()

Since: API Level 1

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

protected void onDisplayHint (int hint)

Since: API Level 8

Gives this view a hint about whether is displayed or not. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.

Parameters
hint A hint about whether or not this view is displayed: VISIBLE or INVISIBLE.

protected void onDraw (Canvas canvas)

Since: API Level 1

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn

protected final void onDrawScrollBars (Canvas canvas)

Since: API Level 7

Request the drawing of the horizontal and the vertical scrollbar. The scrollbars are painted only if they have been awakened first.

Parameters
canvas the canvas on which to draw the scrollbars

protected void onFinishInflate ()

Since: API Level 1

Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.

Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.

protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)

Since: API Level 1

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters
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.

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Since: API Level 1

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Since: API Level 1

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()).

Parameters
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.

protected void onOverScrolled (int scrollX, int scrollY, boolean clampedX, boolean clampedY)

Since: API Level 9

Called by overScrollBy(int, int, int, int, int, int, int, int, boolean) to respond to the results of an over-scroll operation.

Parameters
scrollX New X scroll value in pixels
scrollY New Y scroll value in pixels
clampedX True if scrollX was clamped to an over-scroll boundary
clampedY True if scrollY was clamped to an over-scroll boundary

protected void onRestoreInstanceState (Parcelable state)

Since: API Level 1

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state The frozen state that had previously been returned by onSaveInstanceState().

protected Parcelable onSaveInstanceState ()

Since: API Level 1

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. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

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.

Returns
  • Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.

protected void onScrollChanged (int l, int t, int oldl, int oldt)

Since: API Level 1

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents). This is typically as a result of scrollBy(int, int) or scrollTo(int, int) having been called.

Parameters
l Current horizontal scroll origin.
t Current vertical scroll origin.
oldl Previous horizontal scroll origin.
oldt Previous vertical scroll origin.

protected boolean onSetAlpha (int alpha)

Since: API Level 1

Invoked if there is a Transform that involves alpha. Subclass that can draw themselves with the specified alpha should return true, and then respect that alpha when their onDraw() is called. If this returns false then the view may be redirected to draw into an offscreen buffer to fulfill the request, which will look fine, but may be slower than if the subclass handles it internally. The default implementation returns false.

Parameters
alpha The alpha (0..255) to apply to the view's drawing
Returns
  • true if the view can draw with the specified alpha.

protected void onSizeChanged (int w, int h, int oldw, int oldh)

Since: API Level 1

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Parameters
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 onVisibilityChanged (View changedView, int visibility)

Since: API Level 8

Called when the visibility of the view or an ancestor of the view is changed.

Parameters
changedView The view whose visibility changed. Could be 'this' or an ancestor view.
visibility The new visibility of changedView: VISIBLE, INVISIBLE or GONE.

protected void onWindowVisibilityChanged (int visibility)

Since: API Level 1

Called when the window containing has change its visibility (between 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.

Parameters
visibility The new visibility of the window.

protected boolean overScrollBy (int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)

Since: API Level 9

Scroll the view with standard behavior for scrolling beyond the normal content boundaries. Views that call this method should override 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.

Parameters
deltaX Change in X in pixels
deltaY Change in Y in pixels
scrollX Current X scroll value in pixels before applying deltaX
scrollY Current Y scroll value in pixels before applying deltaY
scrollRangeX Maximum content scroll range along the X axis
scrollRangeY Maximum content scroll range along the Y axis
maxOverScrollX 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.
Returns
  • true if scrolling was clamped to an over-scroll boundary along either axis, false otherwise.

protected final void setMeasuredDimension (int measuredWidth, int measuredHeight)

Since: API Level 1

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.

Parameters
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.

protected boolean verifyDrawable (Drawable who)

Since: API Level 1

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
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.
Returns
  • boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.