ScrollView

Extends Composite

A composite that allows its content to overflow either vertically (default) or horizontally. Since the ScrollView does not compute its own size, the width and height must be defined by the respective layout properties (e.g. either width or left and right must be specified).

Import this type with “const {ScrollView} = require('tabris');

Android iOS
ScrollView on Android ScrollView on iOS

Methods

scrollToX(offset, options)

Parameters:

  • offset: number
    • the offset to scroll to in dip.
  • options: {animate?: boolean} [Optional]
    • an additional object to control the animation. Set to {animate:false} to scroll without an animation.
      Returns:this

Scrolls to the given horizontal offset. Give {animate:false} as the second parameter to suppress the animation.

scrollToY(offset, options)

Parameters:

  • offset: number
    • the offset to scroll to in dip.
  • options: {animate?: boolean} [Optional]
    • an additional object to control the animation. Set to {animate:false} to scroll without an animation.
      Returns:this

Scrolls to the given vertical offset. Give {animate:false} as the second parameter to suppress the animation.

Properties

direction

Type: string, supported values: vertical, horizontal, default: vertical

Specifies the scrolling direction of the scroll composite.This property can only be set on widget creation. Once set, it cannot be changed anymore.

offsetX

read-only Type: number

The horizontal scrolling position in dip.

offsetY

read-only Type: number

The vertical scrolling position in dip.

Events

offsetXChanged

Fired when the offsetX property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: number The new value of offsetX.

offsetYChanged

Fired when the offsetY property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: number The new value of offsetY.

scrollX

Fired while scrolling horizontally.

Event Parameters

  • target: this The widget the event was fired on.

  • offset: number Indicates the current horizontal scrolling position.

scrollY

Fired while scrolling vertically.

Event Parameters

  • target: this The widget the event was fired on.

  • offset: number Indicates the current vertical scrolling position.

Example

  1. const {Button, ScrollView, TextView, ui} = require('tabris');
  2. // Create a horizontal scroll view and populate it with text views
  3. let scrollView = new ScrollView({
  4. left: 0, right: 0, top: '40%', bottom: '40%',
  5. direction: 'horizontal',
  6. background: '#234'
  7. }).appendTo(ui.contentView);
  8. for (let i = 0; i <= 50; i++) {
  9. new TextView({
  10. left: i * 30 + 20, centerY: 0, width: 30,
  11. textColor: 'white',
  12. text: i + '°'
  13. }).appendTo(scrollView);
  14. }
  15. new Button({
  16. left: 16, bottom: 16,
  17. text: 'scroll'
  18. }).on('select', () => scrollView.scrollToX(310))
  19. .appendTo(ui.contentView);

See also

原文:

https://youjingyu.github.io/Tabris-Documention/?folderName=widgets&pageName=ScrollView.html