简体   繁体   English

Android ListView滚动到顶部而不突出显示第一项

[英]Android ListView scroll to top without highlighting first item

I use list.setSelection(0); 我用list.setSelection(0); to scroll the ListView to top, but this also unfortunately sets the highlight color of the top list item. ListView滚动到顶部,但是不幸的是,这也设置了顶部列表项的突出显示颜色。

I just want it to scroll to top and not set the highlight color. 我只希望它滚动到顶部而不设置突出显示颜色。 (Android API 10) (Android API 10)

You could use smoothScrollToPositionFromTop . 您可以使用smoothScrollToPositionFromTop

try 尝试

list.smoothScrollToPositionFromTop(0, 0);

or 要么

list.smoothScrollToPositionFromTop(list.getHeaderViewsCount(), 0);

if your ListView has header. 如果您的ListView有标题。

You can try 你可以试试

list.smoothScrollBy(0, 1000);

or 要么

if (!ListView.isStackFromBottom()) {
    ListView.setStackFromBottom(true);
}
ListView.setStackFromBottom(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM