【发布时间】:2018-07-21 07:06:02
【问题描述】:
加载时,我试图让 ListView 滚动到底部。然而,什么也没有发生。这是我在 Android 上运行的:
<ListView #lv row="0" [items]="myItems" class="list-group" separatorColor="transparent" [itemTemplateSelector]="templateSelector">
然后在 Typescript 我有:
@ViewChild('lv') listViewElem: ElementRef;
private scrollToBottom(lv: ListView) {
if (lv && lv.items.length > 0) {
lv.scrollToIndex(lv.items.length - 1);
lv.refresh();
}
}
ngAfterViewInit() {
setTimeout(() => {
this.scrollToBottom(this.listViewElem.nativeElement);
}, 500);
}
当我调试时,一切似乎都很好。在 ngAfterViewInit 中,定义了 listViewElem,在 scrollToBottomView 中将 items 设置为一个包含 6 个元素的数组。但是当它被调用时,什么都没有发生。
我还尝试在视图中添加一个按钮,当您单击时,我会调用相同的逻辑来查看它是否只是加载时初始化顺序的事情,但这也不起作用:
<Label row="0" text="Click Me" filter(tap)="scrollNow()"></Label>
还有:
public scrollNow(): void {
this.scrollToBottom(this.listViewElem.nativeElement);
}
有什么想法吗?
【问题讨论】:
标签: android listview scroll nativescript angular5