Android APIs
public class

SwipeRefreshLayout

extends ViewGroup
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v4.widget.SwipeRefreshLayout

Class Overview

The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. The activity that instantiates this view should add an OnRefreshListener to be notified whenever the swipe to refresh gesture is completed. The SwipeRefreshLayout will notify the listener each and every time the gesture is completed again; the listener is responsible for correctly determining when to actually initiate a refresh of its content. If the listener determines there should not be a refresh, it must call setRefreshing(false) to cancel any visual indication of a refresh. If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.

This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child. This view will also be made the target of the gesture and will be forced to match both the width and the height supplied in this layout. The SwipeRefreshLayout does not provide accessibility events; instead, a menu item must be provided to allow refresh of the content wherever this gesture is used.

Summary

Nested Classes
interface SwipeRefreshLayout.OnRefreshListener Classes that wish to be notified when the swipe gesture correctly triggers a refresh should implement this interface. 
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
SwipeRefreshLayout(Context context)
Simple constructor to use when creating a SwipeRefreshLayout from code.
SwipeRefreshLayout(Context context, AttributeSet attrs)
Constructor that is called when inflating SwipeRefreshLayout from XML.
Public Methods
boolean canChildScrollUp()
void draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
boolean isRefreshing()
void onAttachedToWindow()
This is called when the view is attached to a window.
void onDetachedFromWindow()
This is called when the view is detached from a window.
boolean onInterceptTouchEvent(MotionEvent ev)
Implement this method to intercept all touch screen motion events.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

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

boolean onTouchEvent(MotionEvent ev)
Implement this method to handle touch screen motion events.
void requestDisallowInterceptTouchEvent(boolean b)
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).
void setColorScheme(int colorRes1, int colorRes2, int colorRes3, int colorRes4)
This method is deprecated. Use setColorSchemeResources(int, int, int, int)
void setColorSchemeColors(int color1, int color2, int color3, int color4)
Set the four colors used in the progress animation.
void setColorSchemeResources(int colorRes1, int colorRes2, int colorRes3, int colorRes4)
Set the four colors used in the progress animation from color resources.
void setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener)
Set the listener to be notified when a refresh is triggered via the swipe gesture.
void setRefreshing(boolean refreshing)
Notify the widget that refresh state has changed.
Protected Methods
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.
[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
void addChildrenForAccessibility(ArrayList<View> children)
Adds the children of a given View for accessibility.
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 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 addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)
Add a listener for attach state changes.
void addOnLayoutChangeListener(View.OnLayoutChangeListener listener)
Add a listener that will be called when the bounds of the view change due to layout processing.
void addTouchables(ArrayList<View> views)
Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.
ViewPropertyAnimator animate()
This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.
void announceForAccessibility(CharSequence text)
Convenience method for sending a TYPE_ANNOUNCEMENT AccessibilityEvent to make an announcement which is related to some sort of a context change for which none of the events representing UI transitions is a good fit.
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.

void bringToFront()
Change the view's z order in the tree, so it's on top of other sibling views.
void buildDrawingCache()

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

void buildDrawingCache(boolean autoScale)

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

void buildLayer()
Forces this view's layer to be created and this view to be rendered into its layer.
boolean callOnClick()
Directly call any attached OnClickListener.
boolean canResolveLayoutDirection()
Check if layout direction resolution can be done.
boolean canResolveTextAlignment()
Check if text alignment resolution can be done.
boolean canResolveTextDirection()
Check if text direction resolution can be done.
boolean canScrollHorizontally(int direction)
Check if this view can be scrolled horizontally in a certain direction.
boolean canScrollVertically(int direction)
Check if this view can be scrolled vertically in a certain direction.
void cancelLongPress()
Cancels a pending long press.
final void cancelPendingInputEvents()
Cancel any deferred high-level input events that were previously posted to the event queue.
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().
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.

void computeScroll()
Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.
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.

AccessibilityNodeInfo createAccessibilityNodeInfo()
Returns an AccessibilityNodeInfo representing this view from the point of view of an AccessibilityService.
void createContextMenu(ContextMenu menu)
Show the context menu for this view.
void destroyDrawingCache()

Frees the resources used by the drawing cache.

WindowInsets dispatchApplyWindowInsets(WindowInsets insets)
Request to apply the given window insets to this view or another view in its subtree.
void dispatchConfigurationChanged(Configuration newConfig)
Dispatch a notification about a resource configuration change down the view hierarchy.
void dispatchDisplayHint(int hint)
Dispatch a hint about whether this view is displayed.
boolean dispatchDragEvent(DragEvent event)
Detects if this View is enabled and has a drag event listener.
void dispatchDraw(Canvas canvas)
Called by draw to draw the child views.
boolean dispatchGenericFocusedEvent(MotionEvent event)
Dispatch a generic motion event to the currently focused view.
boolean dispatchGenericMotionEvent(MotionEvent event)
Dispatch a generic motion event.
boolean dispatchGenericPointerEvent(MotionEvent event)
Dispatch a generic motion event to the view under the first pointer.
boolean dispatchHoverEvent(MotionEvent event)
Dispatch a hover event.
boolean dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
boolean dispatchKeyEventPreIme(KeyEvent event)
Dispatch a key event before it is processed by any input method associated with the view hierarchy.
boolean dispatchKeyShortcutEvent(KeyEvent event)
Dispatches a key shortcut event.
boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
Dispatches an AccessibilityEvent to the View first and then to its children for adding their text content to the event.
void dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Called by restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children.
void dispatchSaveInstanceState(SparseArray<Parcelable> container)
Called by saveHierarchyState(android.util.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 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 dispatchVisibilityChanged(View changedView, int visibility)
Dispatch a view visibility change down the view hierarchy.
void dispatchWindowFocusChanged(boolean hasFocus)
Called when the window containing this view gains or loses window focus.
void dispatchWindowSystemUiVisiblityChanged(int visible)
Dispatch callbacks to onWindowSystemUiVisibilityChanged(int) down the view hierarchy.
void dispatchWindowVisibilityChanged(int visibility)
Dispatch a window visibility change down the view hierarchy.
void draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
View findFocus()
Find the view in the hierarchy rooted at this view that currently has focus.
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.
void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags)
Finds the Views that contain given text.
boolean fitSystemWindows(Rect insets)
This method was deprecated in API level 20. As of API XX use dispatchApplyWindowInsets(WindowInsets) to apply insets to views. Views should override onApplyWindowInsets(WindowInsets) or use setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener) to implement handling their own insets.
View focusSearch(int direction)
Find the nearest view in the specified direction that can take focus.
void forceLayout()
Forces this view to be laid out during the next layout pass.
static int generateViewId()
Generate a value suitable for use in setId(int).
int getAccessibilityLiveRegion()
Gets the live region mode for this View.
AccessibilityNodeProvider getAccessibilityNodeProvider()
Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.
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.
float getBottomFadingEdgeStrength()
Returns the strength, or intensity, of the bottom faded edge.
int getBottomPaddingOffset()
Amount by which to extend the bottom fading region.
float getCameraDistance()
Gets the distance along the Z axis from the camera to this view.
Rect getClipBounds()
Returns a copy of the current clipBounds.
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.
ContextMenu.ContextMenuInfo getContextMenuInfo()
Views should implement this if they have extra information to associate with the context menu.
static int getDefaultSize(int size, int measureSpec)
Utility to return a default size.
Display getDisplay()
Gets the logical display to which the view's window has been attached.
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 framewo rk should discard touches when the view's window is obscured by another visible window.
boolean getFitsSystemWindows()
Check for state of setFitsSystemWindows(boolean).
ArrayList<View> getFocusables(int direction)
Find and return all focusable views that are descendants of this view, possibly including this view if it is focusable itself.
void getFocusedRect(Rect r)
When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method.
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 getHorizontalScrollbarHeight()
Returns the height of the horizontal scrollbar.
int getId()
Returns this view's identifier.
int getImportantForAccessibility()
Gets the mode for determining whether this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.
boolean getKeepScreenOn()
Returns whether the screen should remain on, corresponding to the current value of KEEP_SCREEN_ON.
KeyEvent.DispatcherState getKeyDispatcherState()
Return the global KeyEvent.DispatcherState for this view's window.
int getLabelFor()
Gets the id of a view for which this view serves as a label for accessibility purposes.
int getLayerType()
Indicates what type of layer is currently associated with this view.
int getLayoutDirection()
Returns the resolved layout direction for this view.
ViewGroup.LayoutParams getLayoutParams()
Get the LayoutParams associated with this view.
final int getLeft()
Left position of this view relative to its parent.
float getLeftFadingEdgeStrength()
Returns the strength, or intensity, of the left faded edge.
int getLeftPaddingOffset()
Amount by which to extend the left fading region.
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 ma sked 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 getMinimumHeight()
Returns the minimum height of the view.
int getMinimumWidth()
Returns the minimum width of the view.
int getNextFocusDownId()
Gets the id of the view to use when the next focus is FOCUS_DOWN.
int getNextFocusForwardId()
Gets the id of the view to use when the next focus is FOCUS_FORWARD.
int getNextFocusLeftId()
Gets the id of the view to use when the next focus is FOCUS_LEFT.
int getNextFocusRightId()
Gets the id of the view to use when the next focus is FOCUS_RIGHT.
int getNextFocusUpId()
Gets the id of the view to use when the next focus is FOCUS_UP.
View.OnFocusChangeListener getOnFocusChangeListener()
Returns the focus-change callback registered for this view.
int getOverScrollMode()
Returns the over-scroll mode for this view.
ViewOverlay getOverlay()
Returns the overlay for this view, creating it if it does not yet exist.
int getPaddingBottom()
Returns the bottom padding of this view.
int getPaddingEnd()
Returns the end padding of this view depending on its resolved layout direction.
int getPaddingLeft()
Returns the left padding of this view.
int getPaddingRight()
Returns the right padding of this view.
int getPaddingStart()
Returns the start padding of this view depending on its resolved layout direction.
int getPaddingTop()
Returns the top padding of this view.
final ViewParent getParent()
Gets the parent of this view.
ViewParent getParentForAccessibility()
Gets the parent for accessibility purposes.
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.
float getRightFadingEdgeStrength()
Returns the strength, or intensity, of the right faded edge.
int getRightPaddingOffset()
Amount by which to extend the right fading region.
View getRootView()

Finds the topmost view in the current view hierarchy.

float getRotation()
The degrees that the view is rotated around the pivot point.
float getRotationX()
The degrees that the view is rotated around the horizontal axis through the pivot point.
float getRotationY()
The degrees that the view is rotated around the vertical axis through the pivot point.
float getScaleX()
The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.
float getScaleY()
The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height.
int getScrollBarDefaultDelayBeforeFade()
Returns the delay before scrollbars fade.
int getScrollBarFadeDuration()
Returns the scrollbar fade duration.
int getScrollBarSize()
Returns the scrollbar size.
int getScrollBarStyle()

Returns the current scrollbar style.

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 getSuggestedMinimumHeight()
Returns the suggested minimum height that the view should use.
int getSuggestedMinimumWidth()
Returns the suggested minimum width that the view should use.
int getSystemUiVisibility()
Returns the last setSystemUiVisibility(int) that this view has requested.
Object getTag(int key)
Returns the tag associated with this view and the specified key.
Object getTag()
Returns this view's tag.
int getTextAlignment()
Return the resolved text alignment.
int getTextDirection()
Return the resolved text direction.
final int getTop()
Top position of this view relative to its parent.
float getTopFadingEdgeStrength()
Returns the strength, or intensity, of the top faded edge.
int getTopPaddingOffset()
Amount by which to extend the top fading region.
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 vertical 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.
int getWindowAttachCount()
WindowId getWindowId()
Retrieve the WindowId for the window this view is currently attached to.
int getWindowSystemUiVisibility()
Returns the current system UI visibility that is currently set for the entire window.
IBinder getWindowToken()
Retrieve a unique token identifying the window this view is attached to.
int getWindowVisibility()
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 hasOnClickListeners()
Return whether this view has an attached OnClickListener.
boolean hasOverlappingRendering()
Returns whether this View has content which overlaps.
boolean hasTransientState()
Indicates whether the view is currently tracking transient state that the app should not need to concern itself with saving and restoring, but that the framework should take special note to preserve when possible.
boolean hasWindowFocus()
Returns true if this view is in a window that currently has window focus.
static View inflate(Context context, int resource, ViewGroup root)
Inflate a view from an XML resource.
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.

void invalidate(Rect dirty)
Mark the area defined by dirty as needing to be drawn.
void invalidate(int l, int t, int r, int b)
Mark the area defined by the rect (l,t,r,b) as needing to be drawn.
void invalidate()
Invalidate the whole view.
void invalidateDrawable(Drawable drawable)
Invalidates the specified Drawable.
boolean isActivated()
Indicates the activation state of this view.
boolean isAttachedToWindow()
Returns true if this view is currently attached to a window.
boolean isClickable()
Indicates whether this view reacts to click events or not.
boolean 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 a hardware accelerated window or not.

boolean isHorizontalFadingEdgeEnabled()

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

boolean isHorizontalScrollBarEnabled()

Indicate whether the horizontal scrollbar should be drawn or not.

boolean isHovered()
Returns true if the view is currently hovered.
boolean isInEditMode()
Indicates whether this View is currently in edit mode.
boolean isInLayout()
Returns whether the view hierarchy is currently undergoing a layout pass.
boolean isInTouchMode()
Returns whether the device is currently in touch mode.
boolean isLaidOut()
Returns true if this view has been through at least one layout since it was last attached to or detached from a window.
boolean isLayoutDirectionResolved()
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 isPaddingOffsetRequired()
If the View draws content inside its padding and enables fading edges, it needs to support padding offsets.
boolean isPaddingRelative()
Return if the padding as been set thru relative values setPaddingRelative(int, int, int, int) or thru
boolean isPressed()
Indicates whether the view is currently in pressed state.
boolean 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 isScrollContainer()
Indicates whether this view is one of the set of scrollable containers in its window.
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 isTextAlignmentResolved()
boolean isTextDirectionResolved()
boolean isVerticalFadingEdgeEnabled()

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

boolean isVerticalScrollBarEnabled()

Indicate whether the vertical scrollbar should be drawn or not.

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.

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 offsetLeftAndRight(int offset)
Offset this view's horizontal location by the specified amount of pixels.
void offsetTopAndBottom(int offset)
Offset this view's vertical location by the specified number of pixels.
void 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.
WindowInsets onApplyWindowInsets(WindowInsets insets)
Called when the view should apply WindowInsets according to its internal policy.
void onAttachedToWindow()
This is called when the view is attached to a window.
void onCancelPendingInputEvents()
Called as the result of a call to cancelPendingInputEvents() on this view or a parent view.
boolean onCheckIsTextEditor()
Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it.
void 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.
InputConnection onCreateInputConnection(EditorInfo outAttrs)
Create a new InputConnection for an InputMethod to interact with the 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.
boolean onDragEvent(DragEvent event)
Handles drag events sent by the system following a call to startDrag().
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.

boolean onFilterTouchEventForSecurity(MotionEvent event)
Filter the touch event to apply security policies.
void onFinishInflate()
Finalize inflating a view from XML.
void onFinishTemporaryDetach()
Called after onStartTemporaryDetach() when the container is done changing the view.
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
boolean onGenericMotionEvent(MotionEvent event)
Implement this method to handle generic motion events.
void onHoverChanged(boolean hovered)
Implement this method to handle hover state changes.
boolean onHoverEvent(MotionEvent event)
Implement this method to handle hover events.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
boolean onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when 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 shortc ut 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 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 onPopulateAccessibilityEvent(AccessibilityEvent event)
Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content.
void onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().
void onRtlPropertiesChanged(int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has been changed.
Parcelable onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.
void onScreenStateChanged(int screenState)
This method is called whenever the state of the screen this view is attached to changes.
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 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 onVisibilityChanged(View changedView, int visibility)
Called when the visibility of the view or an ancestor of the view is changed.
void onWindowFocusChanged(boolean hasWindowFocus)
Called when the window containing this view gains or loses focus.
void onWindowSystemUiVisibilityChanged(int visible)
Override to find out when the window's requested system UI visibility has changed, that is the value returned by getWindowSystemUiVisibility().
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.
boolean performAccessibilityAction(int action, Bundle arguments)
Performs the specified accessibility action on the view.
boolean performClick()
Call this view's OnClickListener, if it is defined.
boolean performHapticFeedback(int feedbackConstant)
BZZZTT!!1!

Provide haptic feedback to the user for this view.

boolean performHapticFeedback(int feedbackConstant, int flags)
BZZZTT!!1!

Like performHapticFeedback(int), with additional options.

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 postInvalidateOnAnimation(int left, int top, int right, int bottom)

Cause an invalidate of the specified area to happen on the next animation time step, typically the next display frame.

void postInvalidateOnAnimation()

Cause an invalidate to happen on the next animation time step, typically the next display frame.

void postOnAnimation(Runnable action)

Causes the Runnable to execute on the next animation time step.

void postOnAnimationDelayed(Runnable action, long delayMillis)

Causes the Runnable to execute on the next animation time step, after the specified amount of time elapses.

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.
void requestApplyInsets()
Ask that a new dispatch of onApplyWindowInsets(WindowInsets) be performed.
void requestFitSystemWindows()
This method was deprecated in API level 20. Use requestApplyInsets() for newer platform versions.
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)
Sends an accessibility event of the given type.
void sendAccessibilityEventUnchecked(AccessibilityEvent event)
This method behaves exactly as sendAccessibilityEvent(int) but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.
void setAccessibilityDelegate(View.AccessibilityDelegate delegate)
Sets a delegate for implementing accessibility support via composition as opposed to inheritance.
void setAccessibilityLiveRegion(int mode)
Sets the live region mode for this view.
void setActivated(boolean activated)
Changes the activated state of this view.
void setAlpha(float alpha)

Sets the opacity of the view.

void setAnimation(Animation animation)
Sets the next animation to play for this view.
void setBackground(Drawable background)
Set the background to a given Drawable, or remove the background.
void setBackgroundColor(int color)
Sets the background color for this view.
void setBackgroundDrawable(Drawable background)
This method was deprecated in API level 16. use setBackground(Drawable) instead
void setBackgroundResource(int resid)
Set the background to a given resource.
fi nal void setBottom(int bottom)
Sets the bottom position of this view relative to its parent.
void setCameraDistance(float distance)

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view.

void setClickable(boolean clickable)
Enables or disables click events for this view.
void setClipBounds(Rect clipBounds)
Sets a rectangular area on this view to which the view will be clipped when it is drawn.
void setContentDescription(CharSequence contentDescription)
Sets the View description.
void setDrawingCacheBackgroundColor(int color)
Setting a solid background color for the drawing cache's bitmaps will improve performance and memory usage.
void setDrawingCacheEnabled(boolean enabled)

Enables or disables the drawing cache.

void setDrawingCacheQuality(int quality)
Set the drawing cache quality of this view.
void setDuplicateParentStateEnabled(boolean enabled)

Enables or disables the duplication of the parent's state into this view.

void setEnabled(boolean enabled)
Set the enabled state of this view.
void setFadingEdgeLength(int length)
Set the size of the faded edge used to indicate that more content in this view is available.
void setFilterTouchesWhenObscured(boolean enabled)
Sets whether the framework should discard touches when the view's window is obscured by another visible window.
void setFitsSystemWindows(boolean fitSystemWindows)
Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of fitSystemWindows(Rect) will be executed.
void setFocusable(boolean focusable)
Set whether this view can receive the focus.
void setFocusableInTouchMode(boolean focusableInTouchMode)
Set whether this view can receive focus while in touch mode.
void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
Set whether this view should have haptic feedback for events such as long presses.
void setHasTransientState(boolean hasTransientState)
Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible.
void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)

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

void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)

Define whether the horizontal scrollbar should be drawn or not.

void setHovered(boolean hovered)
Sets whether the view is currently hovered.
void setId(int id)
Sets the identifier for this view.
void setImportantForAccessibility(int mode)
Sets how to determine whether this view is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.
void setKeepScreenOn(boolean keepScreenOn)
Controls whether the screen should remain on, modifying the value of KEEP_SCREEN_ON.
void setLabelFor(int id)
Sets the id of a view for which this view serves as a label for accessibility purposes.
void setLayerPaint(Paint paint)
Updates the Paint object used with the current layer (used only if the current layer type is not set to LAYER_TYPE_NONE).
void setLayerType(int layerType, Paint paint)

Specifies the type of layer backing this view.

void setLayoutDirection(int layoutDirection)
Set the layout direction for this view.
void setLayoutParams(ViewGroup.LayoutParams params)
Set the layout parameters associated with this view.
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.
final void setMeasuredDimension(int measuredWidth, int measuredHeight)

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

void setMinimumHeight(int minHeight)
Sets the minimum height of the view.
void setMinimumWidth(int minWidth)
Sets the minimum width of the view.
void setNextFocusDownId(int nextFocusDownId)
Sets the id of the view to use when the next focus is FOCUS_DOWN.
void setNextFocusForwardId(int nextFocusForwardId)
Sets the id of the view to use when the next focus is FOCUS_FORWARD.
void setNextFocusLeftId(int nextFocusLeftId)
Sets the id of the view to use when the next focus is FOCUS_LEFT.
void setNextFocusRightId(int nextFocusRightId)
Sets the id of the view to use when the next focus is FOCUS_RIGHT.
void setNextFocusUpId(int nextFocusUpId)
Sets the id of the view to use when the next focus is FOCUS_UP.
void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
Set an View.OnApplyWindowInsetsListener to take over the policy for applying window insets to this view.
void setOnClickListener(View.OnClickListener l)
Register a callback to be invoked when this view is clicked.
void setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)
Register a callback to be invoked when the context menu for this view is being built.
void setOnDragListener(View.OnDragListener l)
Register a drag event listener callback object for this View.
void setOnFocusChangeListener(View.OnFocusChangeListener l)
Register a callback to be invoked when focus of this view changed.
void setOnGenericMotionListener(View.OnGenericMotionListener l)
Register a callback to be invoked when a generic motion event is sent to this view.
void setOnHoverListener(View.OnHoverListener l)
Register a callback to be invoked when a hover event is sent to this view.
void setOnKeyListener(View.OnKeyListener l)
Register a callback to be invoked when a hardware key is pressed in this view.
void setOnLongClickListener(View.OnLongClickListener l)
Register a callback to be invoked when this view is clicked and held.
void setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener l)
Set a listener to receive callbacks when the visibility of the system bar changes.
void setOnTouchListener(View.OnTouchListener l)
Register a callback to be invoked when a touch event is sent to this view.
void setOverScrollMode(int overScrollMode)
Set the over-scroll mode for this view.
void setPadding(int left, int top, int right, int bottom)
Sets the padding.
void setPaddingRelative(int start, int top, int end, int bottom)
Sets the relative padding.
void setPivotX(float pivotX)
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 setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade)
Define the delay before scrollbars fade.
void setScrollBarFadeDuration(int scrollBarFadeDuration)
Define the scrollbar fade duration.
void setScrollBarSize(int scrollBarSize)
Define the scrollbar size.
void setScrollBarStyle(int style)

Specify the style of the scrollbars.

void setScrollContainer(boolean isScrollContainer)
Change whether this view is one of the set of scrollable containers in its window.
void setScrollX(int value)
Set the horizontal scrolled position of your view.
void setScrollY(int value)
Set the vertical scrolled position of your view.
void 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 or other screen/window decorations be changed.
void setTag(int key, Object tag)
Sets a tag associated with this view and a key.
void setTag(Object tag)
Sets the tag associated with this view.
void setTextAlignment(int textAlignment)
Set the text alignment.
void setTextDirection(int textDirection)
Set the text direction.
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.
String toString()
Returns a string containing a concise, human-readable description of this object.
void unscheduleDrawable(Drawable who)
Unschedule any events associated with the given Drawable.
void unscheduleDrawable(Drawable who, Runnable what)
Cancels a scheduled action on a drawable.
boolean verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.
boolean willNotCacheDrawing()
Returns whether or not this View can cache its drawing or not.
boolean willNotDraw()
Returns whether or not this View draws on its own.
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public SwipeRefreshLayout (Context context)

Simple constructor to use when creating a SwipeRefreshLayout from code.

public SwipeRefreshLayout (Context context, AttributeSet attrs)

Constructor that is called when inflating SwipeRefreshLayout from XML.

Public Methods

public boolean canChildScrollUp ()

Returns
  • Whether it is possible for the child view of this layout to scroll up. Override this if the child view is a custom view.

public void draw (Canvas canvas)

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(android.graphics.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 boolean isRefreshing ()

Returns
  • Whether the SwipeRefreshWidget is actively showing refresh progress.

public void onAttachedToWindow ()

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(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

public void onDetachedFromWindow ()

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

public boolean onInterceptTouchEvent (MotionEvent ev)

Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

  1. You will receive the down event here.
  2. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
  3. For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
  4. If you return true from here, you will not receive any following events: the target view will receive the same event but with the action ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.

Parameters
ev The motion event being dispatched down the hierarchy.
Returns
  • Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.

public void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

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.

public boolean onTouchEvent (MotionEvent ev)

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

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

public void requestDisallowInterceptTouchEvent (boolean b)

Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.

Parameters
b True if the child does not want the parent to intercept touch events.

public void setColorScheme (int colorRes1, int colorRes2, int colorRes3, int colorRes4)

This method is deprecated.
Use setColorSchemeResources(int, int, int, int)

public void setColorSchemeColors (int color1, int color2, int color3, int color4)

Set the four colors used in the progress animation. The first color will also be the color of the bar that grows in response to a user swipe gesture.

public void setColorSchemeResources (int colorRes1, int colorRes2, int colorRes3, int colorRes4)

Set the four colors used in the progress animation from color resources. The first color will also be the color of the bar that grows in response to a user swipe gesture.

public void setOnRefreshListener (SwipeRefreshLayout.OnRefreshListener listener)

Set the listener to be notified when a refresh is triggered via the swipe gesture.

public void setRefreshing (boolean refreshing)

Notify the widget that refresh state has changed. Do not call this when refresh is triggered by a swipe gesture.

Parameters
refreshing Whether or not the view should show refresh progress.

Protected Methods

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

Called from layout when this view should assign a size and position to each of its children. 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