如何让项目的高度在ListView? [英] how to get height of the item in a listview?
问题描述
我使用的是customadapter并重写getView()方法。在这种方法我称之为view.getHeight(),它在列表视图返回0,我想找出高度(像素)的每个项目。并找出它是在屏幕上。所以,如果我有在列表视图中10个项目,才有可能找出屏幕(像素)5号项目的位置,我想找出项目的y。左上角。
CustomArrayAdapter适配器=新CustomArrayAdapter(这一点,R.layout.rowlayout,mydizi);
查看标题=(查看)getLayoutInflater()膨胀(R.layout.listview_header_row,NULL);
lv.addHeaderView(头);
lv.setAdapter(适配器);
视图Viewlist产品= lv.getChildAt(5 - lv.getFirstVisiblePosition());
viewList.getLocationOnScreen(位置);
有关在列表mList给定可见行nPosition,你可以通过视图的位置:
//寻源的位置和目的地账户的ListView行
INT [] =位置{0,0};视图Viewlist产品= mList.getChildAt(nPosition - mList.getFirstVisiblePosition());
viewList.getLocationOnScreen(位置);
但你可能需要从getView(),即填充列表之后。
之外的做到这一点I am using a customadapter and overriding the getView() method. In this method I call view.getHeight() which returns 0. I would like to find out the height (in pixel) of each item in the listview. And find out where it is on the screen. So If I have 10 items in the list view is it possible to find out where the 5th item position on the screen(in pixel) I would like to find out the y of the item. top left corner.
CustomArrayAdapter adapter = new CustomArrayAdapter(this,R.layout.rowlayout,mydizi);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
lv.addHeaderView(header);
lv.setAdapter(adapter);
View viewList = lv.getChildAt(5 - lv.getFirstVisiblePosition());
viewList.getLocationOnScreen(location);
For a given VISIBLE row nPosition in list mList, you can get the location of the view via:
// find the position of the source and destination accounts ListView rows
int[] location = {0,0};
View viewList = mList.getChildAt(nPosition - mList.getFirstVisiblePosition());
viewList.getLocationOnScreen(location);
but you'll likely need to do this from outside your getView(), i.e. after the list is populated.
这篇关于如何让项目的高度在ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!