smoothScrollToPositionFromTop和smoothScrollToPosition的区别

原文地址:https://blog.csdn.net/static_void_james/article/details/74353295#commentsedit

学习Android群英传看到书中的smoothScrollToPosition时,很多博客说这个方法移动listview不准确,却没有说明具体原因,最终找到了原博主这篇博客,感谢原博主。

首先,学一个英语短语:
such that 使得满足…的条件
两者的API文档分别如下:

AbsListView.smoothScrollToPositionFromTop:
Smoothly scroll to the specified adapter position.The view will scroll such that the indicated position is displayed offset pixels below the top edge of the view.
流畅地滚动到指定位置。这个listview将滚动,直到指定position位置的view显示在离顶端offset个像素的位置。

ListView.smoothScrollToPosition
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
流畅地滚动到指定位置。这个listview将滚动,直到指定position位置的view显示出来。

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

smoothScrollToPosition:只是滑到指定位置的view在屏幕上显示出来,只要显示出来,就不再滑动,不管显示在屏幕最上方还是最下方。有时候会失效,就是因为已经指定位置的view已经显示在屏幕上了,如果想显示在指定的位置,需要使用smoothScrollToPositionFromTop,使指定位置的view显示在离父布局顶端N个像素的位置。或者指定smoothScrollToPosition,参数列表中的position一个偏移量,使未显示的view显示出来,将需要摆放位置的view向特定方向挤压过去,以达到指定view的位置的目的。

view:The view whose scroll state is being reported
firstVisibleItem:the index of the first visible cell (ignore if visibleItemCount == 0)
visibleItemCount:the number of visible cells
totalItemCount:the number of items in the list adaptor

        </div>
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-778f64ae39.css" rel="stylesheet">
            </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值