如何让多个android listview同时使用一个滚动条

重新设置ListView的高度

 

/**
* 设置listview高度,注意listview子项必须为LinearLayout才能调用该方法
* @param listview listview
*
*/
public static void setListViewHeight(ListView listview)
{
int totalHeight = 0;
ListAdapter adapter= listview.getAdapter();
if(null != adapter)
{
for (int i = 0; i <adapter.getCount(); i++)
{
View listItem = adapter.getView(i, null, listview);
if (null != listItem)
{
listItem.measure(0, 0);//注意listview子项必须为LinearLayout才能调用该方法
totalHeight += listItem.getMeasuredHeight();
}
}

ViewGroup.LayoutParams params = listview.getLayoutParams();
params.height = totalHeight + (listview.getDividerHeight() * (listview.getCount() - 1));
listview.setLayoutParams(params);
}
}

相关文章:

  • 2022-01-13
  • 2022-01-24
  • 2022-12-23
  • 2021-05-28
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-01-29
  • 2021-12-03
  • 2021-10-17
相关资源
相似解决方案