I have a LinearLayout that I want to programatically add an arbitrary number of ImageViews to, until they fill the width of the screen. How can I determine how many this is? Is there some way to know if the next one will cause it to not fit anymore? Is there some way to detect it doesn't fit after I've added it (and remove the last one in that case)?
Asked
Active
Viewed 41 times
0
-
Sounds like you're looking for a Flow Layout. This post has some options: http://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android – Mike M. Aug 12 '14 at 22:05
1 Answers
0
You can do the following:
1.get x,y location of each view at runtime use the following method-
public void getLocationOnScreen (int[] location)
Added in API level 1 Computes the coordinates of this view on the screen. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.
Parameters location an array of two integers in which to hold the coordinates
2.Calculate the empty portion of the screen by subtracting x,y coordinates of the bottom view from the height/width of the screen.
3.Check whether the empty portion> the portion required to draw next view.

rupesh jain
- 3,410
- 1
- 14
- 22