I want to calculate the width of dynamically create multiple buttons based on their text contents to fit them in the layout without using any third party library.for example:-
https://i.stack.imgur.com/dyUuK.png
Asked
Active
Viewed 219 times
1

deepmala singh
- 221
- 1
- 8
-
So, you want to get the total width X, that the parent layout should have in order to fit all the buttons? – azizbekian Mar 25 '17 at 13:27
-
@azizbekian ,yes..if buttons doesn't fit the row of layout then that button should get down to the second row of layout and so on. – deepmala singh Mar 25 '17 at 13:36
-
Highly simplified solution would be to implement a custom view, measure all childViews, ask them to layout base on constrain you have set for them. OR use a third party library that does exactly the same. – Ankit Apr 21 '17 at 12:20
2 Answers
0
The layout you are talking about is FlowLayout
. Romain Guy (one of Android Framework engineers) answers to a similar question here.
Here you can see a simple implementation of FlowLayout
given by Romain.
Also, you can have a look at source code of FlexboxLayout that has much more advanced implementation of that functionality and is maintained by google.

Community
- 1
- 1

azizbekian
- 60,783
- 13
- 169
- 249
0
try using: enter link description here
Fully customizable widget that help alot.

deepmala singh
- 221
- 1
- 8