We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当然问题也好解决,自定义一个ListView继承LoadMoreListView,重写onMeasure方法,再动态设置listView的高度即可。
ListView
LoadMoreListView
onMeasure
listView
public class MyListView extends LoadMoreListView {}
然后重写onMeasure:
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
动态设置listView的高度:
public void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params) }
最后
listView.setAdapter(adapter); setListViewHeightBasedOnChildren(listView);
在布局layout.xml中的ListView就是MyListView
The text was updated successfully, but these errors were encountered:
No branches or pull requests
当然问题也好解决,自定义一个
ListView
继承LoadMoreListView
,重写onMeasure
方法,再动态设置listView
的高度即可。public class MyListView extends LoadMoreListView {}
然后重写onMeasure:
动态设置listView的高度:
最后
在布局layout.xml中的ListView就是MyListView
The text was updated successfully, but these errors were encountered: