【问题标题】:Scroll to end of FlatList with contentContainerStyle使用 contentContainerStyle 滚动到 FlatList 的末尾
【发布时间】:2019-03-28 12:35:24
【问题描述】:

正如标题所说,我有一个带有contentContainerStyle 的 FlatList,用于在列表底部创建一些空间。当我尝试使用scrollToEnd() 时,列表似乎没有滚动到底部,在这种情况下是contentContainerStyle 创建的额外空间的末尾。有什么办法可以让列表自动滚动到最后吗?截至目前,scrollToEnd() 只滚动到我列表中最后一项附近的某个位置,而不是最后

<FlatList
 {..}
 contentContainerStyle={{paddingBottom:500}}
 {..}
/>

【问题讨论】:

    标签: react-native


    【解决方案1】:

    也许您应该尝试使用“scrollToIndex()”并传递平面列表中的最后一个索引。 有关该方法的文档,请参见此处:https://facebook.github.io/react-native/docs/flatlist#scrolltoindex

    例如,您可以执行以下操作:

    flatList1.scrollToIndex({
       animated: false,
       index: this.state.flastListData.length
    });
    

    【讨论】:

      【解决方案2】:

      所以过了一段时间我想出了一个想法,写一个滚动函数,获取内容高度和滚动高度,当这个高度改变时滚动。

      scrollToBottom() {
          const pointToScroll = this.contentHeight - this.scrollViewHeight;
          const scrollResponder = this.refs.scrollView.getScrollResponder();
          scrollResponder.scrollResponderScrollTo({x: 0, y: pointToScroll, true});
      }
      

      【讨论】:

        猜你喜欢
        • 2017-10-16
        • 2018-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-30
        • 2016-01-17
        • 2012-04-10
        • 1970-01-01
        相关资源
        最近更新 更多