Added in API level 1
Deprecated in API level 16

Gallery


open class Gallery : AbsSpinner, GestureDetector.OnGestureListener
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.AdapterView<android.widget.SpinnerAdapter>
   ↳ android.widget.AbsSpinner
   ↳ android.widget.Gallery

A view that shows items in a center-locked, horizontally scrolling list.

The default values for the Gallery assume you will be using android.R.styleable#Theme_galleryItemBackground as the background for each View given to the Gallery from the Adapter. If you are not doing this, you may need to adjust some Gallery properties, such as the spacing.

Views given to the Gallery should use Gallery.LayoutParams as their layout parameters type.

Summary

Nested classes
open

Gallery extends LayoutParams to provide a place to hold current Transformation information along with previous position/transformation info.

XML attributes
android:animationDuration Sets how long a transition animation should run (in milliseconds) when layout has changed.
android:gravity Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
android:spacing
Inherited XML attributes
Inherited constants
Public constructors
Gallery(context: Context!)

Gallery(context: Context!, attrs: AttributeSet!)

Gallery(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Gallery(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Boolean

open Unit

open ViewGroup.LayoutParams!

open CharSequence!

open Boolean

open Boolean
onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float)

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

Handles left, right, and clicking

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

open Unit

Notified when a long press occurs with the initial on down MotionEvent that trigged it.

open Boolean
onScroll(e1: MotionEvent?, e2: MotionEvent, distanceX: Float, distanceY: Float)

open Unit

open Boolean

open Boolean

open Unit
setAnimationDuration(animationDurationMillis: Int)

Sets how long the transition animation should run when a child view changes position.

open Unit

Whether or not to callback on any getOnItemSelectedListener() while the items are being flinged.

open Unit
setGravity(gravity: Int)

Describes how the child views are aligned.

open Unit
setSpacing(spacing: Int)

Sets the spacing between items in a Gallery

open Unit
setUnselectedAlpha(unselectedAlpha: Float)

Sets the alpha of items that are not selected in the Gallery.

open Boolean

open Boolean

open Boolean
showContextMenuForChild(originalView: View!)

open Boolean
showContextMenuForChild(originalView: View!, x: Float, y: Float)

Protected methods
open Boolean

open Int

open Int

open Int

open Unit

open ViewGroup.LayoutParams!

open ViewGroup.LayoutParams!

open Int
getChildDrawingOrder(childCount: Int, i: Int)

open Boolean

open ContextMenu.ContextMenuInfo!

open Unit

open Unit
onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?)

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

Inherited functions
Inherited properties

XML attributes

android:animationDuration

android:animationDuration
Sets how long a transition animation should run (in milliseconds) when layout has changed. Only relevant if animation is turned on.

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

android:gravity

android:gravity
Specifies how an object should position its content, on both the X and Y axes, within its own bounds.

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

Constant Value Description
bottom 50 Push object to the bottom of its container, not changing its size.
center 11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
center_horizontal 1 Place object in the horizontal center of its container, not changing its size.
center_vertical 10 Place object in the vertical center of its container, not changing its size.
clip_horizontal 8 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
clip_vertical 80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
end 800005 Push object to the end of its container, not changing its size.
fill 77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
fill_horizontal 7 Grow the horizontal size of the object if needed so it completely fills its container.
fill_vertical 70 Grow the vertical size of the object if needed so it completely fills its container.
left 3 Push object to the left of its container, not changing its size.
right 5 Push object to the right of its container, not changing its size.
start 800003 Push object to the beginning of its container, not changing its size.
top 30 Push object to the top of its container, not changing its size.

android:spacing

android:spacing

Public constructors

Added in API level 1
Gallery(context: Context!)
Added in API level 1
Gallery(
    context: Context!,
    attrs: AttributeSet!)
Added in API level 1
Gallery(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)
Added in API level 21
Gallery(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

dispatchKeyEvent

Added in API level 1
open fun dispatchKeyEvent(event: KeyEvent!): Boolean

Deprecated: Deprecated in Java.

Parameters
event KeyEvent!: The key event to be dispatched.
Return
Boolean True if the event was handled, false otherwise.

dispatchSetSelected

Added in API level 1
open fun dispatchSetSelected(selected: Boolean): Unit

Deprecated: Deprecated in Java.

Parameters
selected Boolean: The new selected state

generateLayoutParams

Added in API level 1
open fun generateLayoutParams(attrs: AttributeSet!): ViewGroup.LayoutParams!

Deprecated: Deprecated in Java.

Parameters
attrs AttributeSet!: the attributes to build the layout parameters from
Return
ViewGroup.LayoutParams! an instance of android.view.ViewGroup.LayoutParams or one of its descendants

getAccessibilityClassName

Added in API level 23
Deprecated in API level 16
open fun getAccessibilityClassName(): CharSequence!

Deprecated: Deprecated in Java.

onDown

Added in API level 1
open fun onDown(e: MotionEvent): Boolean

Deprecated: Deprecated in Java.

Parameters
e MotionEvent: The down motion event. This value cannot be null.

onFling

Added in API level 1
open fun onFling(
    e1: MotionEvent?,
    e2: MotionEvent,
    velocityX: Float,
    velocityY: Float
): Boolean

Deprecated: Deprecated in Java.

Parameters
e1 MotionEvent?: The first down motion event that started the fling. A null event indicates an incomplete event stream or error state.
e2 MotionEvent: The move motion event that triggered the current onFling. This value cannot be null.
velocityX Float: The velocity of this fling measured in pixels per second along the x axis.
velocityY Float: The velocity of this fling measured in pixels per second along the y axis.
Return
Boolean true if the event is consumed, else false

onKeyDown

Added in API level 1
open fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Deprecated: Deprecated in Java.

Handles left, right, and clicking

Parameters
keyCode Int: a key code that represents the button pressed, from android.view.KeyEvent
event KeyEvent!: the KeyEvent object that defines the button action
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 1
open fun onKeyUp(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Deprecated: Deprecated in Java.

Parameters
keyCode Int: A key code that represents the button pressed, from android.view.KeyEvent.
event KeyEvent!: The KeyEvent object that defines the button action.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onLongPress

Added in API level 1
open fun onLongPress(e: MotionEvent): Unit

Deprecated: Deprecated in Java.

Notified when a long press occurs with the initial on down MotionEvent that trigged it.

Parameters
e MotionEvent: This value cannot be null.

onScroll

Added in API level 1
open fun onScroll(
    e1: MotionEvent?,
    e2: MotionEvent,
    distanceX: Float,
    distanceY: Float
): Boolean

Deprecated: Deprecated in Java.

Parameters
e1 MotionEvent?: The first down motion event that started the scrolling. A null event indicates an incomplete event stream or error state.
e2 MotionEvent: The move motion event that triggered the current onScroll. This value cannot be null.
distanceX Float: The distance along the X axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.
distanceY Float: The distance along the Y axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.
Return
Boolean true if the event is consumed, else false

onShowPress

Added in API level 1
open fun onShowPress(e: MotionEvent): Unit

Deprecated: Deprecated in Java.

Parameters
e MotionEvent: The down motion event This value cannot be null.

onSingleTapUp

Added in API level 1
open fun onSingleTapUp(e: MotionEvent): Boolean

Deprecated: Deprecated in Java.

Parameters
e MotionEvent: The up motion event that completed the first tap This value cannot be null.
Return
Boolean true if the event is consumed, else false

onTouchEvent

Added in API level 1
open fun onTouchEvent(event: MotionEvent!): Boolean

Deprecated: Deprecated in Java.

Parameters
event MotionEvent!: The motion event.
Return
Boolean True if the event was handled, false otherwise.

setAnimationDuration

Added in API level 1
open fun setAnimationDuration(animationDurationMillis: Int): Unit

Deprecated: Deprecated in Java.

Sets how long the transition animation should run when a child view changes position. Only relevant if animation is turned on.

Parameters
animationDurationMillis Int: The duration of the transition, in milliseconds.

setCallbackDuringFling

Added in API level 1
open fun setCallbackDuringFling(shouldCallback: Boolean): Unit

Deprecated: Deprecated in Java.

Whether or not to callback on any getOnItemSelectedListener() while the items are being flinged. If false, only the final selected item will cause the callback. If true, all items between the first and the final will cause callbacks.

Parameters
shouldCallback Boolean: Whether or not to callback on the listener while the items are being flinged.

setGravity

Added in API level 1
open fun setGravity(gravity: Int): Unit

Deprecated: Deprecated in Java.

Describes how the child views are aligned.

Parameters
gravity Int:

setSpacing

Added in API level 1
open fun setSpacing(spacing: Int): Unit

Deprecated: Deprecated in Java.

Sets the spacing between items in a Gallery

Parameters
spacing Int: The spacing in pixels between items in the Gallery

setUnselectedAlpha

Added in API level 1
open fun setUnselectedAlpha(unselectedAlpha: Float): Unit

Deprecated: Deprecated in Java.

Sets the alpha of items that are not selected in the Gallery.

Parameters
unselectedAlpha Float: the alpha for the items that are not selected.

showContextMenu

Added in API level 1
open fun showContextMenu(): Boolean

Deprecated: Deprecated in Java.

Return
Boolean true if the context menu was shown, false otherwise

showContextMenu

Added in API level 24
Deprecated in API level 16
open fun showContextMenu(
    x: Float,
    y: Float
): Boolean

Deprecated: Deprecated in Java.

Parameters
x Float: the X coordinate in pixels relative to the view to which the menu should be anchored, or Float#NaN to disable anchoring
y Float: the Y coordinate in pixels relative to the view to which the menu should be anchored, or Float#NaN to disable anchoring
Return
Boolean true if the context menu was shown, false otherwise

showContextMenuForChild

Added in API level 1
open fun showContextMenuForChild(originalView: View!): Boolean

Deprecated: Deprecated in Java.

Parameters
originalView View!: the source view where the context menu was first invoked
Return
Boolean true if the context menu was shown, false otherwise

showContextMenuForChild

Added in API level 24
Deprecated in API level 16
open fun showContextMenuForChild(
    originalView: View!,
    x: Float,
    y: Float
): Boolean

Deprecated: Deprecated in Java.

Parameters
originalView View!: the source view where the context menu was first invoked
x Float: the X coordinate in pixels relative to the original view to which the menu should be anchored, or Float#NaN to disable anchoring
y Float: the Y coordinate in pixels relative to the original view to which the menu should be anchored, or Float#NaN to disable anchoring
Return
Boolean true if the context menu was shown, false otherwise

Protected methods

checkLayoutParams

Added in API level 1
protected open fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean

Deprecated: Deprecated in Java.

computeHorizontalScrollExtent

Added in API level 1
protected open fun computeHorizontalScrollExtent(): Int

Deprecated: Deprecated in Java.

Return
Int the horizontal extent of the scrollbar's thumb

computeHorizontalScrollOffset

Added in API level 1
protected open fun computeHorizontalScrollOffset(): Int

Deprecated: Deprecated in Java.

Return
Int the horizontal offset of the scrollbar's thumb

computeHorizontalScrollRange

Added in API level 1
protected open fun computeHorizontalScrollRange(): Int

Deprecated: Deprecated in Java.

Return
Int the total horizontal range represented by the horizontal scrollbar

dispatchSetPressed

Added in API level 1
protected open fun dispatchSetPressed(pressed: Boolean): Unit

Deprecated: Deprecated in Java.

Parameters
pressed Boolean: The new pressed state

generateDefaultLayoutParams

Added in API level 1
protected open fun generateDefaultLayoutParams(): ViewGroup.LayoutParams!

Deprecated: Deprecated in Java.

Return
ViewGroup.LayoutParams! a set of default layout parameters or null

generateLayoutParams

Added in API level 1
protected open fun generateLayoutParams(p: ViewGroup.LayoutParams!): ViewGroup.LayoutParams!

Deprecated: Deprecated in Java.

Parameters
p ViewGroup.LayoutParams!: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Return
ViewGroup.LayoutParams! an instance of android.view.ViewGroup.LayoutParams or one of its descendants

getChildDrawingOrder

Added in API level 1
protected open fun getChildDrawingOrder(
    childCount: Int,
    i: Int
): Int

Deprecated: Deprecated in Java.

Parameters
drawingPosition the drawing order position.
Return
Int the container position of a child for this drawing order position.

getChildStaticTransformation

Added in API level 1
protected open fun getChildStaticTransformation(
    child: View!,
    t: Transformation!
): Boolean

Deprecated: Deprecated in Java.

Parameters
child View!: The child view whose static transform is being requested
t Transformation!: The Transformation which will hold the result
Return
Boolean true if the transformation was set, false otherwise

getContextMenuInfo

Added in API level 1
protected open fun getContextMenuInfo(): ContextMenu.ContextMenuInfo!

Deprecated: Deprecated in Java.

Return
ContextMenu.ContextMenuInfo! Extra information about the item for which the context menu should be shown. This information will vary across different subclasses of View.

onAttachedToWindow

Added in API level 1
protected open fun onAttachedToWindow(): Unit

Deprecated: Deprecated in Java.

onFocusChanged

Added in API level 1
protected open fun onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect?
): Unit

Deprecated: Deprecated in Java.

Parameters
gainFocus Boolean: True if the View has focus; false otherwise.
direction Int: 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. Value is android.view.View#FOCUS_BACKWARD, android.view.View#FOCUS_FORWARD, android.view.View#FOCUS_LEFT, android.view.View#FOCUS_UP, android.view.View#FOCUS_RIGHT, or android.view.View#FOCUS_DOWN
previouslyFocusedRect Rect?: 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.

onLayout

Added in API level 1
protected open fun onLayout(
    changed: Boolean,
    l: Int,
    t: Int,
    r: Int,
    b: Int
): Unit

Deprecated: Deprecated in Java.

Parameters
changed Boolean: 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