You are reading 12.6.0. See this page in 13.4.1.
Titanium.UI.ScrollableView
Extends Titanium.UI.ViewTitanium.Proxy
A view that encapsulates a horizontally-scrolling set of child views, known as pages, navigable using its built-in horizontal swipe gestures.
| Android | iOS |
|---|---|
![]() |
Use the Titanium.UI.createScrollableView method or <ScrollableView> Alloy element to create
a scrollable view.
The ScrollableView supports an on-screen paging control to indicate whether a previous or next
page exists. When the paging control is enabled on iOS, by default it appears as
small dots on the bottom of the screen, whereas Android displays arrows on the left and
right-hand sides.
Use the cacheSize property to cache views inside the scrollable view. This can be required when
using complex view structures in the scrollable view (e.g. map views) and the app might crash if no
proper cache size is specified. See the Titanium.UI.ScrollableView.cacheSize documentation for more
infos regarding view caching.
Only the scroll event exists for the ScrollableView on Android. To support others, child
views may be added to pages, and event listeners added to these views instead of the pages
themselves.
In a previous Titanium version for iOS, the maxZoomScale and minZoomScale properties were
removed for performance and parity reasons. As they still remain in Titanium.UI.ScrollView,
the equivalent functionality may be obtained by adding a ScrollView to ScrollableView. See
the "Simple Scrollable View with 2 Zoomable Images" example for a demonstration.
Examples
Simple Scrollable View with 3 Views
Create three views and assign them as pages to a scrollable view.
var win = Ti.UI.createWindow();
var view1 = Ti.UI.createView({ backgroundColor:'#123' });
var view2 = Ti.UI.createView({ backgroundColor:'#246' });
var view3 = Ti.UI.createView({ backgroundColor:'#48b' });
var scrollableView = Ti.UI.createScrollableView({
views:[view1,view2,view3],
showPagingControl:true
});
win.add(scrollableView);
win.open();
Simple Scrollable View with 2 Zoomable Images
Create two scroll views, each containing an image view, and assign them as pages to a scrollable view.
var win = Ti.UI.createWindow();
var img1 = Ti.UI.createImageView({
image:'http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/' +
'Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/' +
'402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg'
});
var img1Wrapper = Ti.UI.createScrollView({
maxZoomScale:4.0,
});
img1Wrapper.add(img1);
var img2 = Ti.UI.createImageView({
image:'http://www.nasa.gov/images/content/' +
'616903main_rover_comparison1600_1600-1200.jpg'
});
var img2Wrapper = Ti.UI.createScrollView({
maxZoomScale:4.0,
});
img2Wrapper.add(img2);
var photosView = Ti.UI.createScrollableView({
showPagingControl:true,
views:[img1Wrapper, img2Wrapper]
});
win.add(photosView);
Scrollable View with multiple visible views
Create three views and assign them as pages to a scrollable view. Each page is narrower than a scrollable view, so multiple views are visible at the same time.
var win = Ti.UI.createWindow();
var view1 = Ti.UI.createView({ backgroundColor:'#123' });
var view2 = Ti.UI.createView({ backgroundColor:'#246' });
var view3 = Ti.UI.createView({ backgroundColor:'#48b' });
// Common params
var params = {
views:[view1,view2,view3],
clipViews:false,
showPagingControl:false,
top: 0
};
if (Ti.Platform.name === 'android') {
// Android specific params
params.padding = {
left:40,
right:40
};
} else {
// iOS specific params
params.width = '90%';
}
var scrollableView = Ti.UI.createScrollableView(params);
win.add(scrollableView);
win.open();
Alloy XML Markup
First example as an Alloy view.
<Alloy>
<Window id="win">
<ScrollableView id="scrollableView" showPagingControl="true">
<View id="view1" backgroundColor="#123">
<Label>View 1</Label>
</View>
<View id="view2" backgroundColor="#246">
<Label>View 2</Label>
</View>
<View id="view3" backgroundColor="#48b">
<Label>View 3</Label>
</View>
</ScrollableView>
</Window>
</Alloy>
Scrollable View with indicator image (iOS only)
Create three views and assign them as pages to a scrollable view. Assign preferred indicator image. After window opens, update second page indicator image.
var win = Ti.UI.createWindow({ extendSafeArea: false });
var view1 = Ti.UI.createView({ backgroundColor:'#123' });
var view2 = Ti.UI.createView({ backgroundColor:'#246' });
var view3 = Ti.UI.createView({ backgroundColor:'#48b' });
var backwardImage = Ti.UI.iOS.systemImage('backward');
var scrollableView = Ti.UI.createScrollableView({
views:[view1,view2,view3],
showPagingControl:true,
preferredIndicatorImage: backwardImage
});
win.add(scrollableView);
win.addEventListener('open', function () {
var forwardImage = Ti.UI.iOS.systemImage('forward');
scrollableView.setIndicatorImageForPage(forwardImage, 1);
});
win.open();
Properties 89
Inherited from Titanium.UI.View
Boolean value to remove the long press notification for the device's accessibility service.
Default: true
Inherited from Titanium.UI.View
Whether the view should be "hidden" from (i.e., ignored by) the accessibility service.
Default: false
Inherited from Titanium.UI.View
Briefly describes what performing an action (such as a click) on the view will do.
Default: null
Inherited from Titanium.UI.View
A succint label identifying the view for the device's accessibility service.
Inherited from Titanium.UI.View
A string describing the value (if any) of the view for the device's accessibility service.
Inherited from Titanium.UI.View
Coordinate of the view about which to pivot an animation.
Inherited from Titanium.UI.View
Current position of the view during an animation.
Inherited from Titanium.Proxy
The name of the API that this proxy corresponds to.
backgroundColor
String | Titanium.UI.ColorInherited from Titanium.UI.View
Background color of the view, as a color name or hex triplet.
Inherited from Titanium.UI.View
Disabled background color of the view, as a color name or hex triplet.
Inherited from Titanium.UI.View
Disabled background image for the view, specified as a local file path or URL.
Inherited from Titanium.UI.View
Focused background color of the view, as a color name or hex triplet.
Inherited from Titanium.UI.View
Focused background image for the view, specified as a local file path or URL.
Inherited from Titanium.UI.View
A background gradient for the view.
Linear and Radial Gradients
The following code excerpt creates two views, one with a linear gradient and one with a radial gradient.
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff',
layout: 'vertical'
});
var radialGradient = Ti.UI.createView({
top: 10,
width: 100,
height: 100,
backgroundGradient: {
type: 'radial',
startPoint: { x: 50, y: 50 },
endPoint: { x: 50, y: 50 },
colors: [ 'red', 'blue'],
startRadius: 50,
endRadius: 0,
backfillStart: true
}
});
var linearGradient = Ti.UI.createView({
top: 10,
width: 100,
height: 100,
backgroundGradient: {
type: 'linear',
startPoint: { x: '0%', y: '50%' },
endPoint: { x: '100%', y: '50%' },
colors: [ { color: 'red', offset: 0.0}, { color: 'blue', offset: 0.25 }, { color: 'red', offset: 1.0 } ],
}
});
win1.add(radialGradient);
win1.add(linearGradient);
win1.open();
backgroundImage
StringInherited from Titanium.UI.View
Background image for the view, specified as a local file path or URL.
Inherited from Titanium.UI.View
Size of the left end cap.
Default: 0
backgroundRepeat
BooleanInherited from Titanium.UI.View
Determines whether to tile a background across a view.
Default: false
Inherited from Titanium.UI.View
Selected background color of the view, as a color name or hex triplet.
Inherited from Titanium.UI.View
Selected background image url for the view, specified as a local file path or URL.
Inherited from Titanium.UI.View
Size of the top end cap.
Default: 0
borderColor
String | Titanium.UI.ColorInherited from Titanium.UI.View
Border color of the view, as a color name or hex triplet.
borderRadius
Number | String | Array<Number> | Array<String>Inherited from Titanium.UI.View
Radius for the rounded corners of the view's border.
Default: 0
borderWidth
NumberInherited from Titanium.UI.View
Border width of the view.
Default: 0
bottom
Number | StringInherited from Titanium.UI.View
View's bottom position, in platform-specific units.
Inherited from Titanium.Proxy
Indicates if the proxy will bubble an event to its parent.
Default: true
Number of pages to cache (pre-render).
Pages are rendered in the range (currentPage +/- (cacheSize - 1)/2), rounded down for even values (i.e. cacheSize=4 renders 3 pages into the cache.) Keep in mind that improved performance (larger cache) will lead to faster performance, but greater memory usage.
Inherited from Titanium.UI.View
View's center position, in the parent view's coordinates.
Inherited from Titanium.UI.View
View's clipping behavior.
Determines whether the previous and next pages are clipped, so that they are not visible adjacent to the current page.
Set to false to allow the previous or next pages to be seen. Note that
ScrollableView's width must be smaller than its parent
view in order to make this property effective on iOS.
For Android you have to set the padding property.
Check the Scrollable View with multiple visible views example for both platforms.
Default: true
currentPage
NumberIndex of the active page.
Since Titanium Mobile Release 3.3.0, using this property to change current page changes the page without animation on iOS and Android.
Color for the current page of the paging control, as a color name or hex triplet.
For information about color values, see the "Colors" section of Titanium.UI.
Default: undefined (system-default white)
Determines whether page bouncing effect is disabled.
Default: false
Inherited from Titanium.UI.View
Base elevation of the view relative to its parent in pixels.
Inherited from Titanium.UI.View
Discards touch related events if another app's system overlay covers the view.
Default: false
Inherited from Titanium.UI.View
Whether view should be focusable while navigating with the trackball.
Default: false
height
Number | StringInherited from Titanium.UI.View
View height, in platform-specific units.
Sets the region where this view responds to gestures.
This property is particularly useful when clipViews
is set to false and the dimension of this view is small, to create a larger area for the
user to perform swipe gestures against.
Note that the x and y values specified are relative to the position of the view.
Default: undefined (hit against size of view)
Inherited from Titanium.UI.View
Adds a horizontal parallax effect to the view
Inherited from Titanium.UI.View
Determines whether the layout has wrapping behavior.
Default: true
id
StringInherited from Titanium.UI.View
View's identifier.
Inherited from Titanium.UI.View
Determines whether to keep the device screen on.
Default: false
layout
StringInherited from Titanium.UI.View
Specifies how the view positions its children. One of: 'composite', 'vertical', or 'horizontal'.
left
Number | StringInherited from Titanium.UI.View
View's left position, in platform-specific units.
Inherited from Titanium.Proxy
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
opacity
NumberInherited from Titanium.UI.View
Opacity of this view, from 0.0 (transparent) to 1.0 (opaque). Defaults to 1.0 (opaque).
Determines whether the paging control is added as an overlay to the view.
If this property is set to true, the view takes up the entire height available in the
parent view and the paging control is placed over the view. It is advisable to set an
appropriate value for pagingControlAlpha
along with this property, so that the underlying view content may be seen properly.
Default: false
Inherited from Titanium.UI.View
When on, animate call overrides current animation if applicable.
Determines the behavior when the user overscolls the view.
Default: Titanium.UI.Android.OVER_SCROLL_ALWAYS
The padding applied to the scrollable view.
Color of the paging control, as a color name or hex triplet.
For information about color values, see the "Colors" section of Titanium.UI.
Default: undefined (system-default gray)
Alpha value of the paging control.
Default: 1
Color of the paging control, as a color name or hex triplet.
For information about color values, see the "Colors" section of Titanium.UI.
Default: black
Height of the paging control, in pixels.
Default: 20
Determines whether the paging control is displayed at the top or bottom of the view.
Set to true for the paging control at the top.
Default: false
Number of milliseconds to wait before hiding the paging control.
Set to less than or equal to 0 to disable timeout, to keep controls displayed.
Default: 3000
The preferred image for indicators, defined using a local filesystem path, or a Blob object containing image data.
Symbol images are recommended. Use Titanium.UI.iOS.systemImage to get system-supplied symbol images. See examples section for usage.
Inherited from Titanium.UI.View
The preview context used in the 3D-Touch feature "Peek and Pop".
Inherited from Titanium.UI.View
Background color of the wrapper view when this view is used as either Titanium.UI.ListView.pullView or Titanium.UI.TableView.headerPullView.
Defaults to undefined. Results in a light grey background color on the wrapper view.
Inherited from Titanium.UI.View
The bounding box of the view relative to its parent, in system units.
right
Number | StringInherited from Titanium.UI.View
View's right position, in platform-specific units.
Inherited from Titanium.UI.View
Clockwise 2D rotation of the view in degrees.
Inherited from Titanium.UI.View
Clockwise rotation of the view in degrees (x-axis).
Inherited from Titanium.UI.View
Clockwise rotation of the view in degrees (y-axis).
Inherited from Titanium.UI.View
Scaling of the view in x-axis in pixels.
Inherited from Titanium.UI.View
Scaling of the view in y-axis in pixels.
Determines whether scrolling is enabled for the view.
If this property is unset or true, scrolling is enabled.
Default: undefined (scrolling enabled)
showPagingControl
BooleanDetermines whether the paging control is visible.
Set to true to show paging control.
Default: false
Inherited from Titanium.UI.View
The size of the view in system units.
Inherited from Titanium.UI.View
Determines keyboard behavior when this view is focused. Defaults to Titanium.UI.Android.SOFT_KEYBOARD_DEFAULT_ON_FOCUS.
Inherited from Titanium.UI.View
The view's tintColor
Default: null
Inherited from Titanium.UI.View
The default text to display in the control's tooltip.
top
Number | StringInherited from Titanium.UI.View
The view's top position.
touchEnabled
BooleanInherited from Titanium.UI.View
Determines whether view should receive touch events.
Default: true
Inherited from Titanium.UI.View
A material design visual construct that provides an instantaneous visual confirmation of touch point.
Default: false
Inherited from Titanium.UI.View
Optional touch feedback ripple color. This has no effect unless touchFeedback is true.
Inherited from Titanium.UI.View
Transformation matrix to apply to the view.
Default: Identity matrix
Inherited from Titanium.UI.View
A name to identify this view in activity transition.
Inherited from Titanium.UI.View
Horizontal location of the view relative to its left position in pixels.
Inherited from Titanium.UI.View
Vertical location of the view relative to its top position in pixels.
Inherited from Titanium.UI.View
Depth of the view relative to its elevation in pixels.
Inherited from Titanium.UI.View
Adds a vertical parallax effect to the view
views
Array<Titanium.UI.View>Sets the pages within this Scrollable View.
viewShadowColor
String | Titanium.UI.Colorsince Android 11.1.0, iPhone 3.3.0, iPad 3.3.0, macOS 9.2.0Inherited from Titanium.UI.View
Determines the color of the shadow.
Inherited from Titanium.UI.View
Determines the offset for the shadow of the view.
Inherited from Titanium.UI.View
Determines the blur radius used to create the shadow.
visible
BooleanInherited from Titanium.UI.View
Determines whether the view is visible.
Default: true
width
Number | StringInherited from Titanium.UI.View
View's width, in platform-specific units.
zIndex
NumberInherited from Titanium.UI.View
Z-index stack order position, relative to other sibling views.
Methods 20
Inherited from Titanium.Proxy
Adds the specified callback as an event listener for the named event.
| Parameters | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. 4 fields
|
Adds a new page to this Scrollable View.
| Parameters | Type | Description |
|---|---|---|
| view | Titanium.UI.View | The page to add. |
Inherited from Titanium.UI.View
Animates this view.
| Parameters | Type | Description |
|---|---|---|
| animation | Titanium.UI.Animation | Dictionary<Titanium.UI.Animation> | Either a dictionary of animation properties or an Animation object. |
| callback? | Callback<Object> | Function to be invoked upon completion of the animation. |
applyProperties
since 3.0.0Inherited from Titanium.Proxy
Applies the properties to the proxy.
| Parameters | Type | Description |
|---|---|---|
| props | Dictionary | A dictionary of properties to apply. |
Inherited from Titanium.UI.View
Removes all previously added motion effects.
convertPointToView
since Android 1.8, iPhone 1.8, iPad 1.8, macOS 9.2.0Inherited from Titanium.UI.View
Translates a point from this view's coordinate system to another view's coordinate system.
| Parameters | Type | Description |
|---|---|---|
| point | Point | A point in this view's coordinate system. If this argument is missing an |
| destinationView | Titanium.UI.View | View that specifies the destination coordinate system to convert to. If this argument is not a view, an exception will be raised. |
Inherited from Titanium.Proxy
Fires a synthesized event to any registered listeners.
| Parameters | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| event? | Dictionary | A dictionary of keys and values to add to the Titanium.Event object sent to the listeners. |
getViewById
since 6.1.0Inherited from Titanium.UI.View
Returns the matching view of a given view ID.
| Parameters | Type | Description |
|---|---|---|
| id | String | The ID of the view that should be returned. Use the |
Inherited from Titanium.UI.View
Hides this view.
| Parameters | Type | Description |
|---|---|---|
| options? | AnimatedOptions | Animation options for Android only. Since SDK 5.1.0 and used only on Android 5.0+ Determines whether to enable a circular reveal animation.
Note that the default here is equivalent to passing in |
insertAt
since 3.3.0Inherited from Titanium.UI.View
Inserts a view at the specified position in the children array.
| Parameters | Type | Description |
|---|---|---|
| params | ViewPositionOptions | Pass an object that specifies the view to insert and optionally at which position (defaults to end) 2 fields
|
insertViewsAt
since 5.4.0Inserts views at the specified position in the views array.
| Parameters | Type | Description |
|---|---|---|
| position | Number | Position(index) in the views array to insert the view |
| views | Array<Titanium.UI.View> | Views to insert. |
moveNext
since 3.3.0Sets the current page to the next consecutive page in Titanium.UI.ScrollableView.views.
Since Titanium Mobile Release 3.3.0, using this method to change current page animates the change on iOS and Android.
movePrevious
since 3.3.0Sets the current page to the previous consecutive page in Titanium.UI.ScrollableView.views.
Since Titanium Mobile Release 3.3.0, using this method to change current page animates the change on iOS and Android.
Inherited from Titanium.Proxy
Removes the specified callback as an event listener for the named event.
| Parameters | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| callback | Callback<Titanium.Event> | Callback function to remove. Must be the same function passed to 4 fields
|
Removes an existing page from this Scrollable View.
On Android, does nothing if the page does not exist in Titanium.UI.ScrollableView.views.
On iOS, throws an exception if the page does not exist in Titanium.UI.ScrollableView.views or the index is invalid.
| Parameters | Type | Description |
|---|---|---|
| view | Number | Titanium.UI.View | A Titanium.UI.View object (all platforms) or integer index (Android and iOS only) of the page to remove. |
Scrolls to the specified page in Titanium.UI.ScrollableView.views.
| Parameters | Type | Description |
|---|---|---|
| view | Number | Titanium.UI.View | An integer index or Titanium.UI.View object to set as the current page. |
Sets the indicator image for the specified page.
Override the indicator image for a specific page. Symbol images are recommended. Use Titanium.UI.iOS.systemImage to get system-supplied symbol images. See examples section for usage.
| Parameters | Type | Description |
|---|---|---|
| image | String | Titanium.Blob | The image for the indicator, defined using a local filesystem path,
or a |
| pageNo | Number | Page number to set the image. |
Inherited from Titanium.UI.View
Makes this view visible.
| Parameters | Type | Description |
|---|---|---|
| options? | AnimatedOptions | Animation options for Android only. Since SDK 5.1.0 and only used on Android 5.0+ Determines whether to enable a circular reveal animation.
Note that the default here is equivalent to passing in |
Inherited from Titanium.UI.View
Stops a running animation.
Inherited from Titanium.UI.View
Returns an image of the rendered view, as a Blob.
| Parameters | Type | Description |
|---|---|---|
| callback? | Callback<Titanium.Blob> | Function to be invoked upon completion. If non-null, this method will be performed asynchronously. If null, it will be performed immediately. |
| honorScaleFactor? | Boolean | Determines whether the image is scaled based on scale factor of main screen. (iOS only) When set to true, image is scale factor is honored. When set to false, the image in the blob has the same dimensions for retina and non-retina devices. |
Events 13
dblclick
iPhoneiPadmacOSFired when the device detects a double click against the view.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
doubletap
iPhoneiPadmacOSFired when the device detects a double tap against this page.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
Fired when the scrolling drag gesture on the view has been completed.
| Event properties | Type | Description |
|---|---|---|
| currentPage | Number | Index of the currently visible view of Titanium.UI.ScrollableView.views. |
| view | Titanium.UI.View | The currently visible view. |
focus
AndroidInherited from Titanium.UI.View
Fired when the view element gains focus.
keypressed
since Android 3.1.0, iPhone 5.4.0, iPad 5.4.0, macOS 9.2.0Inherited from Titanium.UI.View
Fired when a hardware key is pressed in the view.
| Event properties | Type | Description |
|---|---|---|
| keyCode | Number | The code for the physical key that was pressed. For more details, see KeyEvent. This API is experimental and subject to change. |
longpress
iPhoneiPadmacOSFired when the device detects a long press against this view.
Generated by touching and holding on a touchscreen, this event occurs before the
finger is lifted again. Note that longpress cannot be generated with a trackball.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
postlayout
since 2.0.0Inherited from Titanium.UI.View
Fired when a layout cycle is finished.
Fired repeatedly as the view is being scrolled.
Prior to 2.1, the scroll event did not fire consistently on all platforms. On iOS,
it fired when scrolling ended, and on Android, it fired when drag ended. You can restore
the pre-2.1 behavior by listening for the scrollEnd or dragEnd events instead.
| Event properties | Type | Description |
|---|---|---|
| currentPage | Number | Index of the currently visible view of Titanium.UI.ScrollableView.views. |
| currentPageAsFloat | Number | Current page index that the view is scrolled to as a float. For
example, if the user is holding the |
| view | Titanium.UI.View | The currently visible view. |
scrollend
since 3.0.0Fired when the view has stopped moving completely.
| Event properties | Type | Description |
|---|---|---|
| currentPage | Number | Index of the currently visible view of Titanium.UI.ScrollableView.views. |
| view | Titanium.UI.View | The currently visible view. |
singletap
iPhoneiPadmacOSFired when the device detects a single tap against this view.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
touchcancel
iPhoneiPadmacOSFired when a touch gesture is interrupted by the device.
Generated in various circumstances, including an incoming call to allow the UI to clean up state.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
touchstart
iPhoneiPadmacOSFired as soon as the device detects a touch gesture against this view.
| Event properties | Type | Description |
|---|---|---|
| x | Number | X coordinate of the event from the |
| y | Number | Y coordinate of the event from the |
twofingertap
iPhoneiPadmacOSFired when the device detects a two-finger tap against the view.
| Event properties | Type | Description |
|---|---|---|
| y | Number | Y coordinate of the event from the |
| x | Number | X coordinate of the event from the |
