【发布时间】:2018-12-13 08:50:47
【问题描述】:
在我的 Nativescript Angular 应用程序中,我在 ScrollView 中有一个 TextView,定义如下:
<ScrollView orientation="vertical" height="70%" width="100%" style="margin-bottom: 1%; background-color:white" (loaded)="onScrollerLoaded($event)">
<TextView
id="terminal" [text]="terminalText" editable="false"
style="color: whitesmoke; background-color: black; font-size: 8%; font-family: monospace" height="100%"
(tap)="onTap($event)" (loaded)="onTerminalLoaded($event)">
</TextView>
</ScrollView>
此元素的目的是充当终端,并快速打印来自蓝牙设备的传入消息。
目前,每当我向 TextView 绑定的 terminalText 变量添加一些文本时,ScrollView 都会滚动回顶部。 我希望能够将 ScrollView 保持在 TextView 的底部。
几点说明:
我正在通过此方法向关联组件类中的terminalText 变量添加文本:
public appendToTerminal(appendStr){
this.terminalText += appendStr;
}
我已尝试实现以下代码,该代码将在 ScrollView 加载后执行:
private scrollIntervalId;
onScrollerLoaded(data: EventData){
if(!this.scrollIntervalId){
this.scrollIntervalId = setInterval(()=>{
this.ngZone.run(() =>
(data.object as any).scrollToVerticalOffset((data.object as any).scrollableHeight, false)
)
}, 10);
}
}
(此尝试基于here给出的解释
我只在 Android 设备上尝试过,因为我无法使用 Apple 设备。
【问题讨论】:
-
在滚动视图加载时它是否工作?
-
@bhavinjalodara 它正在工作
标签: nativescript angular2-nativescript