Search code examples
androidviewgroup

behaviour of addViewInLayout() of ViewGroup in android


I am creating custom ViewGroup in which I am using onLayout method in which I call the addViewInLayout() of the ViewGroup but it is adding the View only horizontally.

How to force it to add View vertically like ListView is doing for Android

Looking for help.


Solution

  • You could try specifying the position via

    child.layout(int left, int top, int right, int bottom)
    

    If you have measured the other views in the view group, you should be able to get the bottom of the bottom most view then

    child.layout(left, viewAbove.getBottom(),right, viewAbove.getBottom()+heightOfTheChild);