Cod*_*ile 25 android listview listactivity
有没有办法可以确保Android列表视图中的给定项目完全可见?
我希望能够以编程方式滚动到特定项目,例如当我按下按钮时.
jau*_*seg 11
试试吧:
public static void ensureVisible(ListView listView, int pos)
{
if (listView == null)
{
return;
}
if(pos < 0 || pos >= listView.getCount())
{
return;
}
int first = listView.getFirstVisiblePosition();
int last = listView.getLastVisiblePosition();
if (pos < first)
{
listView.setSelection(pos);
return;
}
if (pos >= last)
{
listView.setSelection(1 + pos - (last - first));
return;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23700 次 |
| 最近记录: |