使用按钮滚动列表视图 [英] Scrolling listview with buttons

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

问题描述

我想通过按按钮滚动列表视图.我正在使用上下两个按钮,当我按下向上按钮时,列表视图应向上移动一行,当我按下向下按钮时,列表视图应向下移动一行.

I want to scroll my listview by pressing the buttons. Am using two buttons up and down and when i press up button the listview should move one row up and when i press down button the listview should move one row down.

我的列表视图基于链接.我在此处找到了一个很好的滚动视图示例. .现在我的问题是我需要使用listview而不是scrollview,它应该增加/减少一行.作为Android的新手,任何人都可以帮助我解决此问题.预先感谢.

My listview is based on this link. I found a good example of scrollview here. Now my question is instead of scrollview i need to use my listview and it should increase/decrease by one row. As am new to android anyone help me in solving this issue. Thanks in advance.

推荐答案

您可以尝试以下任一方法:

You can try either of the following:

直接滚动:

getListView().setSelection(int);

为了流畅滚动:

getListView().smoothScrollToPosition(int);

示例代码:

public View.OnClickListener onChk = new View.OnClickListener() {
             public void onClick(View v) {

                 int index = list.getFirstVisiblePosition();
                 getListView().smoothScrollToPosition(index+1); // For increment. 

}
});

但是,您只需要处理一种情况,即只有顶部视图的一半或一部分可见.

However you need to handle one case, that is if only half or part of the view at the top is visible.

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

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