android - Nativescript 无法让 ListView 滚动到底部

标签 android listview scroll nativescript angular5

加载时,我试图让 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 中,项目被设置为一个包含 6 个元素的数组。但是当它被调用时什么也没有发生。

我也试过只在 View 中添加一个按钮,当您单击时,我会调用相同的逻辑来查看它是否只是加载时初始化顺序的事情,但这也不起作用:

  <Label row="0" text="Click Me" filter(tap)="scrollNow()"></Label>

并且:

 public scrollNow(): void {
     this.scrollToBottom(this.listViewElem.nativeElement);
  }

有什么想法吗?

最佳答案

请问您为什么要在 scrollToIndex 之后立即尝试 lv.refresh();,因为刷新会重新加载 ListView,它只会返回开始。

关于android - Nativescript 无法让 ListView 滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48723991/

相关文章:

jquery - 使用 jQuery 滚动页面

android - 在 ScrollView 中列出

css - jmpress : Scrolling on Absolutely Positioned Element (Slide) with auto height

android - 从 backstack 恢复 Fragment 时更改 EditText 值

android - 从 RxJava2 迁移到 Kotlin 协程

android - 是否可以在 Google+ API 中阅读所有传入的互动帖子?

android - 当 TabHost 出现在 Activity 中时,EditText 使用硬键盘失去焦点

c# - 我的 ListView 显示重复项

Android:提取列表中TextView的字符串

java - ListView 获取一个 OnCheckedChange 位置时出错