Created
February 19, 2017 13:20
-
-
Save RichardSilveira/c34a1c18a61de8656178a5e649476137 to your computer and use it in GitHub Desktop.
retrieving total height for listView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void getTotalHeightofListView(ListView listView) { | |
ListAdapter mAdapter = listView.getAdapter(); | |
int totalHeight = 0; | |
int listWidth = listView.getMeasuredWidth(); | |
for (int i = 0; i < mAdapter.getCount(); i++) { | |
View mView = mAdapter.getView(i, null, listView); | |
mView.measure( | |
View.MeasureSpec.makeMeasureSpec(listWidth, View.MeasureSpec.EXACTLY), | |
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | |
totalHeight += mView.getMeasuredHeight(); | |
Log.w("HEIGHT" + i, String.valueOf(totalHeight)); | |
} | |
ViewGroup.LayoutParams params = listView.getLayoutParams(); | |
params.height = totalHeight | |
+ (listView.getDividerHeight() * (mAdapter.getCount() - 1)); | |
listView.setLayoutParams(params); | |
listView.requestLayout(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment