在列表视图应用平滑滚动 [英] Apply smooth scrolling on List View

查看:178
本文介绍了在列表视图应用平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个链接答案跨越列表视图的一个项目在一时间在屏幕上。这是为我工作,但滚动,通过该项目向上移动,并配合屏幕工作不顺利的动画。

我搜查,发现该方法的 setSelectionFromTop 是导致此。

但是,如果我使用 smoothScrollToPosition ,然后我的要求在屏幕上满足一个项目我没有兑现。

请帮我this.What我768,16为了达到一举两得


  1. 在屏幕上同时适合列表视图中的一项

  2. 滚动应该工作顺利


解决方案

第一,同时在屏幕上显示只有一个项目,你需要设置每个项目的高度匹配的ListView的高度。

 公共查看getView(INT位置,查看convertView,父母的ViewGroup){
    ...
    INT totalHeight = listView.getHeight();
    INT的rowHeight = totalHeight / getCount将();
    //设置行高度为各行的
    ...

由于只有一个项目显示的时间,在您使用setSelectionFromTop()或smoothScrollToPosition(),它最终将具有相同的结果。所以,你可以使用smoothScrollToPosition()了。

另一种方式来做到这一点是尝试设置的选择。

  listView.setSelection(位置)
listView.setSelectionAfterHeaderView()

setSelectionAfterHeaderView将滚动ListView控件到合适的位置。

希望这有助于。

I am following the answer on this link to span one item of listview at a time on screen. It is working for me but the scrolling and the animation by which item moves up and fits to screen are not working smooth.

I searched and found the method setSelectionFromTop is causing this.

But if i use smoothScrollToPosition then my requirement to fit one item on screen i not fulfilled.

Please help me on this.What shoud I do in order to achieve both

  1. Fit one item of listview at a time on screen
  2. Scrolling should work smooth

解决方案

First, to fit only one item on the screen at a time, you need to set the height of each item to match the height of the ListView.

public View getView(int position, View convertView, ViewGroup parent) {
    ...
    int totalHeight = listView.getHeight();
    int rowHeight = totalHeight / getCount();
    // Set the row height for each of the rows
    ...

With only one item showing at a time, where you use setSelectionFromTop() or smoothScrollToPosition(), it will end up with the same result. So you can use smoothScrollToPosition() now.

Another way to do it is to try setting the selection.

listView.setSelection(position)
listView.setSelectionAfterHeaderView()

setSelectionAfterHeaderView will scroll the ListView to the right position.

Hope this helps.

这篇关于在列表视图应用平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆