Android的ListView的中心选择 [英] Android ListView center selection

查看:156
本文介绍了Android的ListView的中心选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示最接近的词一个ListView匹配搜索。

例如,如果我搜索嗨我知道在ListView结果如下



...

您好

喜5

喜五



突出

....

我使用

  ListView.setSelection(wordList.indexOf(搜索内容));
ListView.setSelected(真);

以上code把所选词喜在顶部和犯规突出的选择。

我想嗨集中定位,选择和自动突出显示。
见下面

...

你好

你好

您好

喜五

喜5

...

什么code,我可以用它来实现上述?

非常感谢。


解决方案

 的ListView视图=(ListView控件)findViewById(R.id.YourListView);INT高度= view.getHeight();
INT itemHeight = view.getChildAt(0).getHeight();
view.setSelectionFromTop(位置,高度/ 2 - itemHeight / 2);


位置(INT)是你想在ListView !!

居中的ListItem

I have a ListView that shows the closest word matches to a search.

For example if I search "hi" I get the following results in the ListView


...
hi
hi five
hi-five
high
highlight
....

I am using

ListView.setSelection(wordList.indexOf(searchWord));
ListView.setSelected(true);

The above code puts the selected word "hi" at the top and doesnt highlight the selection.

I want the "hi" to be centrally positioned , selected and highlighted automatically. See below

...
hello
hello there
hi
hi-five
hi five
...

What code can I use to achieve the above?

Many thanks.

解决方案

ListView view = (ListView)findViewById(R.id.YourListView);

int height = view.getHeight();
int itemHeight = view.getChildAt(0).getHeight();
view.setSelectionFromTop(position, height/2 - itemHeight/2);


The position (int) is the listitem you want to center in the listview!!

这篇关于Android的ListView的中心选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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