![]() Public class FlowLayout extends ViewGroup else if (MeasureSpec.getMode(heightMeasureSpec) = MeasureSpec. Here is the custom class where you can achive layout like following with adding dynamicaly view (Also called FlowLayout). SetMeasuredDimension(resolveSize(width, widthMeasureSpec), Their inclusion is purely to serve as a demonstration. Int height = currentHeight + maxChildHeight + getPaddingBottom() For example, the following picture shows an applet using the flow layout manager (its default layout manager) to position three buttons: Here is the code for this applet: Note: The following code example includes classes that do not appear in this specification. MaxChildHeight = Math.max(maxChildHeight, child.getMeasuredHeight()) ĬurrentWidth += child.getMeasuredWidth() + spacing Width = Math.max(width, currentWidth - spacing) If (growHeight & (breakLine || ((currentWidth + child.getMeasuredWidth()) > widthLimit)))ĬurrentHeight += maxChildHeight + mVerticalSpacing Int widthMode = MeasureSpec.getMode(widthMeasureSpec) īoolean growHeight = widthMode != MeasureSpec.UNSPECIFIED Int widthLimit = MeasureSpec.getSize(widthMeasureSpec) - getPaddingRight() The following change fixes the problem of "last child is clipped if on a new line": void onMeasure(int widthMeasureSpec, int heightMeasureSpec) ![]() I cleaned up a bit the computation (there was a weird use of "height" vs. When the very last child is the one being put on a new line, then the height was not properly computed. Looking in details at the algorithm it seems to be a very simple mistake in the calculation of the height. I could find one myself and I saw, as others, that some children were clipped. I don't have enough reputation to post a comment to Romain Guy's answer but that's where this answer should be (I created an account just to share my edit).Īnyway, I see other people have found out his pretty cool FlowLayout solution has some issues.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |