返回介绍

ScrollView

发布于 2020-10-20 06:58:13 字数 5539 浏览 1096 评论 0 收藏 0

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

AndroidiOS
ScrollView on AndroidScrollView 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

const {Button, ScrollView, TextView, ui} = require('tabris');

// Create a horizontal scroll view and populate it with text views

let scrollView = new ScrollView({
  left: 0, right: 0, top: '40%', bottom: '40%',
  direction: 'horizontal',
  background: '#234'
}).appendTo(ui.contentView);

for (let i = 0; i <= 50; i++) {
  new TextView({
    left: i * 30 + 20, centerY: 0, width: 30,
    textColor: 'white',
    text: i + '°'
  }).appendTo(scrollView);
}

new Button({
  left: 16, bottom: 16,
  text: 'scroll'
}).on('select', () => scrollView.scrollToX(310))
  .appendTo(ui.contentView);

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文