有没有办法找到当前显示在列表中的ListView项目的高度而不在布局xml文件中自己设置它?
我试过了
View listItem = listAdapter.getView(currentIndex, null, listView);
listItem.measure(MeasureSpec.EXACTLY, MeasureSpec.UNSPECIFIED);
int itemHeight = listItem.getMeasuredHeight();
Run Code Online (Sandbox Code Playgroud)
虽然它最初工作,但它决定在启动一个新的仿真器会话后在measure()调用期间抛出一个Null Pointer Exception.
我正在尝试做的是在程序选择时将短项列表中的项目(只有2或3个完整项目可见)置于中心位置.