Created
July 31, 2016 08:03
-
-
Save vincent1086/4c3ac59e0a8ac9b260448c4d75e85e07 to your computer and use it in GitHub Desktop.
Android - ListAdapter Children Measure
This file contains 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
private int measureContentWidth(ListAdapter adapter) { | |
// Menus don't tend to be long, so this is more sane than it looks. | |
int width = 0; | |
View itemView = null; | |
int itemType = 0; | |
final int widthMeasureSpec = | |
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); | |
final int heightMeasureSpec = | |
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); | |
final int count = adapter.getCount(); | |
for (int i = 0; i < count; i++) { | |
final int positionType = adapter.getItemViewType(i); | |
if (positionType != itemType) { | |
itemType = positionType; | |
itemView = null; | |
} | |
if (mMeasureParent == null) { | |
mMeasureParent = new FrameLayout(mContext); | |
} | |
itemView = adapter.getView(i, itemView, mMeasureParent); | |
itemView.measure(widthMeasureSpec, heightMeasureSpec); | |
width = Math.max(width, itemView.getMeasuredWidth()); | |
} | |
return width; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment